I offer a ready-made template for Zabbix and a script in Python, for auto-detection of new numbers of the Zadarma provider (new, in the sense of the numbers you purchased).
The template has several triggerger and basic information about the numbers. The script works with the Zadarma API or with the MySQL database.
To work with MySQL, you need to pre-set the data in advance in crown or directly from the dialplan using a separate script.
Both scripts under the cut.
zadarma_number.pyThe script must be put in the directory with scripts for the zabbiz agent, I have it
/etc/zabbix/scripts/
Also, give it launch permissions and just in case change the owner and the zabbix group:
chmod +x /etc/zabbix/scripts/zadarma_number.py chown zabbix:zabbix /etc/zabbix/scripts/zadarma_number.py
Theoretically, the work with the database may be more relevant, since the script for folding information there can be run after each call. Thus, the info in the database will probably be a bit more relevant than direct work with the API directly from Zabbix.
In the Zabbix template, the {$ FORCE_API} macro forces the script to work with the Zadarma API.
The macro {$ CUT} is used to divide the string of the SIP-URI request into parts before and after the "@".
The script has several keys to run.
Without keys or with the –l option, the script will give a list of numbers in the json format, which is suitable for autodiscovering numbers in zabbix.
Help for script keys:usage: Zadarma for Zabbix [-h] [-l] [-n phone number] [-S] [-g] [-e] [-d] [-s]
[-m] [-a] [-b] [-f] [-c [0,1,2] or none]
This program is designed to monitor the numbers of the provider Zadarma and
Originally conceived as a script for a zabbiz agent.
optional arguments: -h, --help show this help message and exit -l, --allnumbers "Show all found phone numbers in a format suitable for zabbix. Running a script without parameters (or with the -f option) leads to the same result." -n phone number, --number phone number "Phone number and -s or -S or -g or -e or -d or -m or -a " -S, --status -g, --start_date -e, --stop_date -d, --description -s, --sip "can be used in combination with "-c"" -m, --monthly_fee "The amount required to renew a phone number or all phone numbers" -a, --autorenew -b, --balance All balance numbers -f, --force_API "Force the use of api, the database is ignored" -c [0,1,2] or none, --cut [0,1,2] or none Used only in conjunction with "-s" 0 - The whole line, 1- Part of the string before "@", 2 - Part of the line after "@"
The keys "-S, -s, -g, -e, -d, -a" are used only in combination with the number
The -m switch can be used with or without a number.
Key -b, only without a number
The -c key with the -s key only
The -f switch forces the use of the API, without it a query is sent to the database and it can be used with any key.
The second script:
API_to_MySql scriptAlso give it launch rights:
chmod +x ./main.py
How to call the script and where to put it, decide for yourself.
To disable the display of information in the console, you must uncomment the line
debug = False
For both scripts to work, you will most likely need to install “requests”
pip install requests
Table for numbers CREATE TABLE IF NOT EXISTS `zadarma_numbers` ( `id` int(10) NOT NULL, `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `number` varchar(12) DEFAULT NULL, `number_name` varchar(60) DEFAULT NULL, `description` varchar(60) NOT NULL DEFAULT '', `sip` varchar(80) DEFAULT NULL, `start_date` datetime NOT NULL, `stop_date` datetime NOT NULL, `monthly_fee` int(5) DEFAULT NULL, `status` int(1) DEFAULT NULL, `channels` int(3) DEFAULT NULL, `autorenew` int(1) DEFAULT NULL ) ENGINE=InnoDB AUTO_INCREMENT=205 DEFAULT CHARSET=utf8; ALTER TABLE `zadarma_numbers` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `number` (`number`), ADD KEY `calldate` (`date`), ADD KEY `accountcode` (`monthly_fee`); ALTER TABLE `zadarma_numbers` MODIFY `id` int(10) NOT NULL AUTO_INCREMENT;
Table for balance CREATE TABLE IF NOT EXISTS `zadarma_balance` ( `id` int(10) NOT NULL, `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `balance` int(10) DEFAULT NULL, `monthly_fee` int(10) DEFAULT NULL ) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8; ALTER TABLE `zadarma_balance` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `balance` (`balance`), ADD KEY `calldate` (`date`); ALTER TABLE `zadarma_balance` MODIFY `id` int(10) NOT NULL AUTO_INCREMENT;
Repository with template, scripts and mysql dumps.