1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Installation und Benutzung der Icinga API</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<meta name="keywords" content="Supervision, Icinga, Icinga, Linux">
<link rel="home" href="index.html" title="Icinga Version 1.0.2 Dokumentation">
<link rel="up" href="ch10.html" title="Kapitel 10. Entwicklung">
<link rel="prev" href="icinga-web-scratch.html" title="Installation des neuen Icinga Web Frontend">
<link rel="next" href="ch11.html" title="Kapitel 11. IDOUtils">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<CENTER><IMG src="../images/logofullsize.png" border="0" alt="Icinga" title="Icinga"></CENTER>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Installation und Benutzung der Icinga API</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="icinga-web-scratch.html">Zurück</a> </td>
<th width="60%" align="center">Kapitel 10. Entwicklung</th>
<td width="20%" align="right"> <a accesskey="n" href="ch11.html">Weiter</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section" title="Installation und Benutzung der Icinga API">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="icinga-api"></a>Installation und Benutzung der Icinga API</h2></div></div></div>
<p>
<span class="bold"><strong>Voraussetzungen</strong></span>
</p>
<p>Sie benötigen installierte und gestartete Versionen von Icinga und IDOUtils oder MKLiveStatus, um die Icinga API nutzen zu
können. </p>
<div class="note" title="Anmerkung" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Anmerkung]" src="../images/note.png"></td>
<th align="left">Anmerkung</th>
</tr>
<tr><td align="left" valign="top">
<p>Falls Sie Icinga noch nicht installiert haben, folgen Sie den Anweisungen in der "<a class="link" href="quickstart-idoutils.html" title="Icinga-Schnellstart mit IDOUtils">quickstart-idoutils</a>- Dokumentation.</p>
</td></tr>
</table></div>
<p> Wenn Sie die IDOUtils Datenbank als Datenquelle verwenden, installieren Sie bitte PHP-PDO.</p>
<p>
<span class="bold"><strong>RHEL/Fedora/CentOS</strong></span>
</p>
Stellen Sie sicher, dass Sie ein Repository/Packages für PHP 5.2.x zur Verfügung haben - RHEL/CentOS unterstützen lediglich 5.1.6
<pre class="programlisting"># yum install php-pdo php-mysql|pgsql </pre>
<p>
<span class="bold"><strong>Debian/Ubuntu</strong></span>
</p>
# apt-get install php5 php5-mysql|pgsql
<p>
<a name="icinga-api_installation"></a>
<span class="bold"><strong>Installation und Konfiguration</strong></span>
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<p>
<span class="bold"><strong>Software</strong></span>
</p>
<p>Klonen Sie von icinga-api.git, um einen neuen Branch zu bekommen:</p>
<pre class="programlisting"> # git clone git://git.icinga.org/icinga-api.git</pre>
<p>oder laden Sie die Software von <a class="link" href="https://git.icinga.org/index?p=icinga-api.git;a=snapshot;h=refs/heads/master;sf=tgz" target="_top">https://git.icinga.org/index?p=icinga-api.git;a=snapshot;h=refs/heads/master;sf=tgz</a>.</p>
</li>
<li class="listitem">
<p>
<span class="bold"><strong>Installation</strong></span>
</p>
<p>Die Icinga API ist innerhalb des Pakets von Icinga Core, IDOUtils und Docs enthalten und wird während 'make install'
mit installiert. Sofern Sie das schon durchgeführt haben, befindet sich die API standardmässig in /usr/local/icinga/share/icinga-api/ und
Sie können diesen Abschnitt überspringen.</p>
<div class="note" title="Anmerkung" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Anmerkung]" src="../images/note.png"></td>
<th align="left">Anmerkung</th>
</tr>
<tr><td align="left" valign="top">
<p>Wenn Sie die Icinga API für das neue Icinga Web benötigen und schon Icinga Core mit den IDOUtils installiert
haben, können Sie diesen Guide verlassen und direkt <a class="link" href="icinga-web-scratch.html" title="Installation des neuen Icinga Web Frontend">Icinga Web</a> installieren.</p>
</td></tr>
</table></div>
<p>
<span class="bold"><strong>Download</strong></span>
</p>
<p>Sie können die Icinga API direkt aus dem GIT Repository beziehen, für einen frischen Clone führen Sie folgenden Befehl aus:</p>
<pre class="programlisting"># git clone git://git.icinga.org/icinga-api.git</pre>
<p>Sofern Sie lediglich ein Update benötigen:</p>
<pre class="programlisting"># cd icinga-api && git pull origin master</pre>
<p>Oder laden Sie einen Snapshot direkt über das Gitweb: <a class="link" href="https://git.icinga.org/index?p=icinga-api.git;a=snapshot;h=refs/heads/master;sf=tgz" target="_top">https://git.icinga.org/index?p=icinga-api.git;a=snapshot;h=refs/heads/master;sf=tgz</a>.</p>
<p>
<span class="bold"><strong>Installation</strong></span>
</p>
<p>Entpacken Sie die Icinga API, führen Sie configure aus und installieren Sie die Icinga API </p>
<pre class="programlisting"># tar xzvf icinga-api-(version).tar.gz</pre>
<p>
</p>
<pre class="programlisting"># ./configure</pre>
<p>Sie können den Präfix definieren, wohin die Icinga API installiert wird sowie den Ort der Systemkonfiguration für Icinga Core
und IDOUtils und die ausführenden Benutzer. All diese Informationen werden bei einer Installation durch das Core Paket direkt
gesetzt. </p>
<pre class="programlisting"># ./configure --datarootdir=/usr/local/icinga/share --sysconfdir=/usr/local/icinga/etc --with-command-user=icinga-cmd --with-command-group=icinga-cmd --with-icinga-user=icinga --with-icinga-group=icinga</pre>
<p>
</p>
<pre class="programlisting"># make install</pre>
</li>
<li class="listitem">
<p>
<span class="bold"><strong>Konfiguration</strong></span>
</p>
<p>Wenn Sie ihr eigenes Addon auf Basis der Icinga API entwickeln möchten, benötigen Sie das folgende assoziative Array. $idoConfig =
array ( </p>
<pre class="programlisting"> $idoConfig = array (
'type' => '<Type of database>',
'host' => '<Database hostname>',
'database' => '<Databasename>',
'user' => '<Username>',
'password' => '<password>',
'persistent' => <true | false>,
'table_prefix' => '<table prefix>',
);</pre>
<p> Beispiel:</p>
<pre class="programlisting"> $idoConfig = array (
'type' => 'mysql',
'host' => 'localhost',
'database' => 'ido',
'user' => 'idouser',
'password' => 'idopassword',
'persistent' => true,
'table_prefix' => 'icinga_',
);</pre>
</li>
</ol></div>
<p>
<a name="icinga-api_use"></a>
<span class="bold"><strong>Benutzung</strong></span>
</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<p>
<span class="bold"><strong>Datenermittlung</strong></span>
</p>
<p>Host-Namen und zugehörige Zustände</p>
<p>Erzeugen Sie eine Instant der Klasse IcingaApi:</p>
<pre class="programlisting"> $api = IcingaApi::getConnection(IcingaApi::CONNECTION_IDO, $idoConfig);</pre>
<p>Erzeugen Sie die
Suchkriterien:</p>
<p>
</p>
<pre class="programlisting"> $apiRes = $api->createSearch()
->setSearchTarget(IcingaApi::TARGET_HOST)
->setResultColumns(array(’HOST_NAME’, ‘HOST_CURRENT_STATE’))
->fetch();</pre>
<p>
</p>
<p>Mit Hilfe von setSearchFilter() können Sie Filter benutzen, um die Suche einzuschränken:</p>
<p>
</p>
<pre class="programlisting"> $apiRes = $api->createSearch()
->setSearchTarget(IcingaApi::TARGET_HOST)
->setResultColumns(array(’HOST_NAME’, ‘HOST_CURRENT_STATE’))
->setSearchFilter(HOST_NAME, ‘Switch%’, IcingaApi::MATCH_LIKE)
->fetch();</pre>
<p>
</p>
</li>
<li class="listitem">
<p>
<span class="bold"><strong>Verarbeiten der Ergebnisse</strong></span>
</p>
<pre class="programlisting"> foreach($apiRes as $apiHandle){
echo ‘Host ‘.$apiHandle->HOST_NAME.’ has state ‘.$apiHandle->HOST_CURRENT_STATE.’<br />’;
}</pre>
<p>Ausgabe ohne Filter:</p>
<pre class="programlisting"> 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</pre>
<p>Ausgabe mit Filter:</p>
<p>
</p>
<pre class="programlisting"> 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</pre>
<p>
</p>
</li>
<li class="listitem">
<p>
<span class="bold"><strong>Kompletter Code ohne die Nutzung von Filtern</strong></span>
</p>
<pre class="programlisting"> <?
// 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 />';
}
?></pre>
<p>Für nähere Informationen werfen Sie bitte einen Blick in das <a class="link" href="http://git.icinga.org/" target="_top">git repository</a> oder
die Beispiele im doc/examples-Verzeichnis.</p>
</li>
</ol></div>
<a class="indexterm" name="id5614871"></a>
<a class="indexterm" name="id5614886"></a>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="icinga-web-scratch.html">Zurück</a> </td>
<td width="20%" align="center"><a accesskey="u" href="ch10.html">Nach oben</a></td>
<td width="40%" align="right"> <a accesskey="n" href="ch11.html">Weiter</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Installation des neuen Icinga Web Frontend </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Zum Anfang</a></td>
<td width="40%" align="right" valign="top"> Kapitel 11. IDOUtils</td>
</tr>
</table>
</div>
<P class="copyright">© 2009-2010 Icinga Development Team, http://www.icinga.org</P>
</body>
</html>
|