Software
Klonen Sie von icinga-api.git, um einen neuen Branch zu bekommen
# git clone git://git.icinga.org/icinga-api.git
oder laden Sie die Software von https://git.icinga.org/index?p=icinga-api.git;a=snapshot;h=refs/heads/master;sf=tgz.
Die Installation
Entpacken Sie die Software und verschieben Sie das Verzeichnis in die Icinga-Sourcecode-Struktur
# tar xzvf icinga-api-(version).tar.gz # mv icinga-api/* /usr/src/icinga-core/module/icinga-api
Rekompilieren Sie den Code (ggf. müssen Sie erneut ./configure ausführen).
# make all # make install
![]() |
Anmerkung |
---|---|
Falls Sie noch kein Icinga haben, dann folgen Sie den Anweisungen in der "quickstart-idoutils" Dokumentation. |
Konfiguration
Die Konfiguration besteht aus einem assoziativen Array.
$idoConfig = array ( 'type' => '<Type of database>', 'host' => '<Database hostname>', 'database' => '<Databasename>', 'user' => '<Username>', 'password' => '<password>', 'persistent' => <true | false>, 'table_prefix' => '<table prefix>', );
Beispiel:
$idoConfig = array ( 'type' => 'mysql', 'host' => 'localhost', 'database' => 'ido', 'user' => 'idouser', 'password' => 'idopassword', 'persistent' => true, 'table_prefix' => 'icinga_', );
Datenermittlung
Host-Namen und zugehörige Zustände
Erzeugen Sie eine Instant der Klasse IcingaApi:
$api = IcingaApi::getConnection(IcingaApi::CONNECTION_IDO, $idoConfig);
Erzeugen Sie die Suchkriterien:
$apiRes = $api->createSearch() ->setSearchTarget(IcingaApi::TARGET_HOST) ->setResultColumns(array(’HOST_NAME’, ‘HOST_CURRENT_STATE’)) ->fetch();
Mit Hilfe von setSearchFilter() können Sie Filter benutzen, um die Suche einzuschränken:
$apiRes = $api->createSearch() ->setSearchTarget(IcingaApi::TARGET_HOST) ->setResultColumns(array(’HOST_NAME’, ‘HOST_CURRENT_STATE’)) ->setSearchFilter(HOST_NAME, ‘Switch%’, IcingaApi::MATCH_LIKE) ->fetch();
Verarbeiten der Ergebnisse
foreach($apiRes as $apiHandle){ echo ‘Host ‘.$apiHandle->HOST_NAME.’ has state ‘.$apiHandle->HOST_CURRENT_STATE.’<br />’; }
Ausgabe ohne Filter:
Host localhost has state 0 Host MySql has state 0 Host router-01 has state 0 Host windows100 has state 0 Host Apache_01 has state 0
Ausgabe mit Filter:
Host switch70 has the current state 0 Host switch71 has the current state 0 Host switch72 has the current state 0 Host switch73 has the current state 0 Host switch74 has the current state 0 Host switch75 has the current state 0 Host switch76 has the current state 0 Host switch77 has the current state 0
Kompletter Code ohne die Nutzung von Filtern
<? // Path to icinga api file $apiFile = ‘icinga-api/IcingaApi.php’; // Database connection $idoConfig = array ( 'type' => 'mysql', 'host' => 'localhost', 'database' => 'ido', 'user' => 'idouser', 'password' => 'idopassword', 'persistent' => true, 'table_prefix' => 'icinga_', ); // Include required files require_once($apiFile); // Instance the class $api = IcingaApi::getConnection(IcingaApi::CONNECTION_IDO, $idoConfig); // Create search $apiRes = $api->createSearch() ->setSearchTarget(IcingaApi::TARGET_HOST) ->setResultColumns(array('HOST_NAME', 'HOST_CURRENT_STATE')) ->fetch(); // Create output foreach($apiRes as $apiHandle){ echo 'Host '.$apiHandle->HOST_NAME.' has the current state '.$apiHandle->HOST_CURRENT_STATE.'<br />'; } ?>
Für nähere Informationen werfen Sie bitte einen Blick in das git repository.
© 2009-2010 Icinga Development Team, http://www.icinga.org