-zabbix 1.0 - not tested (yet) on 1.1-
I needed to quickly add numerous hosts to my zabbix database (150 switches). I proceeded this way:
. creation of a template for this elements (both items and triggers/actions)
. creation of a text file containing hosts (hostnames;ip-address)
. used the add_host function in a php script
Here's the text file sample (this file is named list.csv):
Here's the PHP code (named add_hosts.php):
When I fire a browser to add_hosts.php, It will inject all hosts found in 'list.csv' to the zabbix database, with all regular checks the add_host function provide.
Off course, a nice php page where you can define you file format, upload you file and run a 'test' before adding should be better... but afterall, this kind of batch population if not a regular action.
Hope this will hope some to quickly populate zabbix with switch list, printer list... the kind of list who are quickly build in text format...
I needed to quickly add numerous hosts to my zabbix database (150 switches). I proceeded this way:
. creation of a template for this elements (both items and triggers/actions)
. creation of a text file containing hosts (hostnames;ip-address)
. used the add_host function in a php script
Here's the text file sample (this file is named list.csv):
Code:
hostname-1;192.168.0.1 hostname-2;192.168.0.2 hostname-3;192.168.0.3 ...
Code:
<?
include "include/config.inc.php";
$page["title"] = "Hosts";
$page["file"] = "hosts.php";
show_header($page["title"],0,0);
insert_confirm_javascript();
// hard variables
$hard_port = "10050"; //cause I want to use ZABBIX agentd on this port
$hard_status = "0"; //cause I want the status to be monitored
$hard_useip = "1"; //cause I want to use IP address
$hard_newgroup = ""; //I did not used it
$hard_host_templateid = "10055"; //This is the hostid of the host template
$hard_groups = array(4,6,3); //This is the groupid of groups I want my new hosts to belong to...
$listing = file("list.csv", "r");
foreach ($listing as $element_number => $element)
{
list($host, $ip) = explode (";", $element);
$result=add_host($host,$hard_port,$hard_status,$hard_useip,$ip,$hard_host_templateid,$hard_newgroup,$hard_groups);
show_messages ($result,"Host added","Cannot add host");
}
?>
Off course, a nice php page where you can define you file format, upload you file and run a 'test' before adding should be better... but afterall, this kind of batch population if not a regular action.
Hope this will hope some to quickly populate zabbix with switch list, printer list... the kind of list who are quickly build in text format...
Comment