Some progress has ben made
I've made some progress towards getting a REST interface working.
Here is an example:
I thought I'd throw the VERY rough draft to get some comments.
Before trying this you will need mod_rewrite running and working on your Apache install. I am running on OpenSuSE 11 and had to change the "AllowOverride" option from None to All in the default-server.conf file.
To install it untar the attached tarball in your zabbix directory. This should create a subdirectory called api. In this directory you will find a .htaccess file. You may need to edit this file depending on your system. The api directory should owned and writeable by the process apache is running as.
You will also need to edit your zabbix.conf.php file in the conf directory. The following variable needs to be added: ZBX_API_BASE_URL here is an example:
The variable should point to the directory which you have placed the API into.
To access the REST interface point your browser to your zabbix server and api directory such as:
You will then be prompted to enter a valid zabbix username and password. Next you will see a JSON object of all active hosts on your system.
The following query:
http://zabbix-server/api/host/<hostid>
Will return information on the one host.
http://zabbix-server/api/host/<hostid>/items
Will return a list of all items associated with a host.
http://zabbix-server/api/history/<itemid>
Will return the most recent history table result for the item given. Only the history table is queried for now.
With history you can also do more complex queries such as:
http://zabbix-server/api/history/<itemid>?starttime=<startime>&endtime=<endtime>&re verse
This will return all values for itemid in the history table where the time is between starttime and endtime and return it in reverse order. One caviat is that the query will automatically limit itself to 100,000 items unless told otherwise. This is done to speed query performance and prevent runaway queries. More information on the available options are in the comments within the zabbixrest.php file.
As you use the interface a log file is generated. You can disable logging by removing the logfile name in the constructor in the index.php file. The log file will log plaintext passwords as it does a dump of the $_SERVER variable. (This is work in progress
)
Right now only GET actions are supported.
I hope to get some progress made on PUT in a few days.
Note: Very little error checking is made on the perameters. You have been warned.
I've made some progress towards getting a REST interface working.
Here is an example:
Code:
[{"clock":"1208763391","value":"0.0166"}]
Before trying this you will need mod_rewrite running and working on your Apache install. I am running on OpenSuSE 11 and had to change the "AllowOverride" option from None to All in the default-server.conf file.
To install it untar the attached tarball in your zabbix directory. This should create a subdirectory called api. In this directory you will find a .htaccess file. You may need to edit this file depending on your system. The api directory should owned and writeable by the process apache is running as.
You will also need to edit your zabbix.conf.php file in the conf directory. The following variable needs to be added: ZBX_API_BASE_URL here is an example:
PHP Code:
$ZBX_API_BASE_URL = "/api";
To access the REST interface point your browser to your zabbix server and api directory such as:
You will then be prompted to enter a valid zabbix username and password. Next you will see a JSON object of all active hosts on your system.
The following query:
http://zabbix-server/api/host/<hostid>
Will return information on the one host.
http://zabbix-server/api/host/<hostid>/items
Will return a list of all items associated with a host.
http://zabbix-server/api/history/<itemid>
Will return the most recent history table result for the item given. Only the history table is queried for now.
With history you can also do more complex queries such as:
http://zabbix-server/api/history/<itemid>?starttime=<startime>&endtime=<endtime>&re verse
This will return all values for itemid in the history table where the time is between starttime and endtime and return it in reverse order. One caviat is that the query will automatically limit itself to 100,000 items unless told otherwise. This is done to speed query performance and prevent runaway queries. More information on the available options are in the comments within the zabbixrest.php file.
As you use the interface a log file is generated. You can disable logging by removing the logfile name in the constructor in the index.php file. The log file will log plaintext passwords as it does a dump of the $_SERVER variable. (This is work in progress
)Right now only GET actions are supported.
I hope to get some progress made on PUT in a few days.
Note: Very little error checking is made on the perameters. You have been warned.
Comment