
Below is a procedure to import a bunch of random users in the web interface.

The scripts of this folder can also be used otherwise (see internal wiki).

# Tools for adding devices, users and agents to XiVO

Devices and user can be inserted from XiVO server or from another computer.
Before using another computer, open `/etc/fail2ban/jail.conf` and set it's IP
to be ignored. Then restart fail2ban.

CSV files with users should not have more than 250 users, otherwise
timeout error may appear and users will not be imported.

**NOTICE: some steps were improved elsewhere, see scripts/demo_agents/README.md**

1. Set XiVO IP
    - Open `add-device-by-mac.py` and change `XIVO_HOST`
    - Open `edit_users-add-device-by-mac.py` and change `XIVO_HOST`

1. Add a web service via XiVO webi
    - Configuration > Management > Web Services Access > Add
    - Login: `ws_user`, pass = `ws_pass` and ACL = `confd.#`

1. Add users
    - Turn off Live reload configuration (Configuration > Management > General)
    - Add context (IPBX configuration > Contexts > Add)
    - Set context type: Internal
    - Add range (Contexts > Edit > Users > Add)
    - Open `users_csv.py`
    - Edit `first_user` (first extension number), `add_users` (how many users to add) and `context`
    - Generate csv file: `python users_csv.py users.csv`
    - Import users via webi

1. Add devices by mac addresses
    - Open `add-device_csv.py`
    - Edit codec lists
    - Install all the codecs via webi
    - Edit `first_user` and `add_users`
    - Generate csv file: `python add-device_csv.py add.csv`
    - Add devices to XiVO: `python add-device-by-mac.py add.csv`

1. Associate devices with users
    - Open `edit_csv.py`
    - Edit `first_user` and `add_users`
    - Generate csv file: `python edit_csv.py edit.csv`
    - Associate devices with users: `python edit_users-add-device-by-mac.py edit.csv`

1. Add agents and associate them with users
    - Create an agents group (Call center > Agents > Add a group)
    - Open database: `sudo -u postgres psql -d asterisk`
    - Get the agents group id: `select * from agentgroup;`
    - Open `agents_sql.py`
    - Edit `first_user`, `add_users`, `context` and `agents_group_id`
    - Generate sql file: `python agents_sql.py /var/tmp/agents.sql`
    - Stop XiVO
    - Apply: `sudo -u postgres psql -d asterisk -a -f /var/tmp/agents.sql`

1. Count users which need to be updated for load test
    ```
    SELECT count(*) FROM usersip
    JOIN userfeatures ON (usersip.name = userfeatures.lastname)
    WHERE userfeatures.firstname='tester'
    AND usersip.host='dynamic';
    ```
1. If count matches, change *host* variable of the users to load tester IP
    ```
    UPDATE usersip
    SET host='192.168.29.239'
    FROM userfeatures
    WHERE usersip.name = userfeatures.lastname
    AND userfeatures.firstname='tester'
    AND usersip.host='dynamic';
    ```
