Skip to content

Instantly share code, notes, and snippets.

@martijngastkemper
Last active August 29, 2015 14:01
Show Gist options
  • Save martijngastkemper/a5a38d65dac89b034c2c to your computer and use it in GitHub Desktop.
Save martijngastkemper/a5a38d65dac89b034c2c to your computer and use it in GitHub Desktop.
Zabbix API uitproberen
<?php
// load ZabbixApi (http://zabbixapi.confirm.ch/)
require 'ZabbixApiAbstract.class.php';
require 'ZabbixApi.class.php';
try {
// connect to Zabbix API
$api = new ZabbixApi("...");
// use extended output for all further requests
$api->setDefaultParams(array(
'output' => 'extend'
));
echo "<h1>eResults diensten</h1>";
$services = array (
'e-mail' => array(
items => array( "net.tcp.service[imap]", "net.tcp.service[pop]", "net.tcp.service[smtp]" ),
hosts => array( "...." )
),
'fifthgear' => array(
items => array( "net.tcp.service[http]" , "mysql.ping"),
hosts => array( "...." )
),
'fifthgear beheer' => array(
items => array( "net.tcp.service[http]" , "mysql.ping"),
hosts => array( "....." )
)
);
foreach( $services as $name => $service )
{
printf( "<h2>%s</h2>", $name );
$items = $api->itemGet( array(
'filter' => array(
'key_' => $service['items'],
'host' => $service['hosts']
)
));
foreach( $items as $item )
{
printf( "%s last value %s (%s)<br />", $item->name, $item->lastvalue, $item->key_ );
}
}
echo "<h1>HoD servers</h1>";
foreach( $api->hostGet() as $host )
{
$ping = $api->itemGet( array( 'hostids' => $host->hostid, 'search' => array( 'key_' => 'agent.ping' )));
printf("<h2>%s (%s)</h2>", $host->host, $ping[0]->lastvalue ? 'online' : 'offline' );
$items = $api->itemGet( array( 'hostids' => $host->hostid ));
foreach( $items as $item )
{
printf( "%s last value %s (%s)<br />", $item->name, $item->lastvalue, $item->key_ );
}
}
} catch(Exception $e) {
// Exception in ZabbixApi catched
echo $e->getMessage();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment