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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>11.3. Keine Icinga API mehr zu installieren</title>
<link rel="stylesheet" href="../stylesheets/icinga-docs.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<meta name="keywords" content="Supervision, Icinga, Nagios, Linux">
<link rel="home" href="index.html" title="Icinga Version 1.14 Dokumentation">
<link rel="up" href="ch11.html" title="Kapitel 11. Entwicklung">
<link rel="prev" href="epnplugins.html" title="11.2. Entwickeln von Plugins für die Nutzung mit Embedded Perl">
<link rel="next" href="icinga-web-api.html" title="11.4. Die Icinga Web REST API">
<script src="../js/jquery-min.js" type="text/javascript"></script><script src="../js/icinga-docs.js" type="text/javascript"></script>
</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">11.3. Keine Icinga API mehr zu installieren</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="epnplugins.html">Zurück</a> </td>
<th width="60%" align="center">Kapitel 11. Entwicklung</th>
<td width="20%" align="right"> <a accesskey="n" href="icinga-web-api.html">Weiter</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section" title="11.3. Keine Icinga API mehr zu installieren">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="icinga-api"></a>11.3. Keine Icinga API mehr zu installieren</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section">11.3.1. <a href="icinga-api.html#idm139734663328496">Installation und Benutzung der Icinga API</a></span></dt>
<dt><span class="section">11.3.2. <a href="icinga-api.html#idm139734663297056">Konfiguration</a></span></dt>
<dt><span class="section">11.3.3. <a href="icinga-api.html#idm139734663294176">Unterstützte Backends</a></span></dt>
</dl></div>
<div class="important" title="Wichtig" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Wichtig]" src="../images/important.png"></td>
<th align="left">Wichtig</th>
</tr>
<tr><td align="left" valign="top">
<p>In der Zeit vor dem Release der Version 1.5 sagten wir unserer Icinga API "Tschüss" und führten ein neues API- und Web-Konzept
ein.</p>
<p>Sie fragen sich vielleicht, was war diese API überhaupt? In der Tat, wenn Sie keine Erweiterungen oder Anpassungen für das neue
Web-Interface entwickelt haben, dann hatten Sie wahrscheinlich wenig Kontakt mit dieser wichtigen Projektkomponente. Als Icinga
konzipiert wurde, war eines der Hauptziele die Unterstützung der Entwicklung von Addons und Plugins. Die API stellte einen Satz von
allgemein verwendbaren Abfragebefehlen zur Verfügung, um die Notwendigkeit zu beseitigen, SQL-Abfragen und generell eine Menge
überflüssigen Code zu schreiben.</p>
<p>Alles war in Ordnung, bis wir uns entschieden, etwas mehr zusätzliche Datenbankflexibilität anzubieten. Als wir neben MySQL
Unterstützung für Oracle and PostgreSQL hinzufügten, gaben wir auch dem Icinga API-Team etwas zusätzliche Arbeit. Mit jeder
Änderung, jedem Bugfix oder neuer Funktionalität mussten Marius, Michael L und Jannis die Abfragen für jedes Datenbank-Backend separat
anpassen. Dieser Prozess war nicht nur kompliziert und fehlerbehaftet, sondern auch ein Zeichen dafür, dass wir eine neue flexiblere
Architektur benötigten.</p>
<p>Mit Icinga 1.5 wurde die externe Icinga API durch eine interne Datenbankschicht namens Doctrine ersetzt und mit Icinga Web
verschmolzen. Ähnlich wie vorher laufen Abfragen durch diese Schicht zwischen der Datenbank (IDOUtils) und dem Web-Interface.
Trotzdem können wir dank Doctrine mehrere Datenbank-Backends benutzen und das Abfragen der Datenbank ist nun viel einfacher. Im
Gegensatz zu SQL nutzt der "object relational mapper" (ORM) die Doctrine Query Language, so dass wir nun die Flexibilität ohne die
Code-Duplizierung haben.</p>
<p><span class="inlinemediaobject"><img src="../images/Architecture_1.5_800px.png"></span></p>
<p>Allerdings funktionieren Abfragen mit der alten API nach wie vor, dank des 'Legacy Layer', der alte API-Abfragen in diesen neuen
ORM-Typ umwandelt. Auf diese Weise erhalten wir die Kompatibilität mit Addons, die für ältere Icinga-Versionen erstellt wurden.
Das Rest-API ist also weiterhin vorhanden als ein Teil von Icinga Web, und erweitert unsere Doctrine-Schicht mit HTTP für Addons, die
nur bestimmte Teile der Überwachungsinformationen benötigen.</p>
<p>Durch den Wegfall einer eigenständigen API wird der durchschnittliche Icinga-Benutzer kaum einen Unterschied bemerken,
außer der Tatsache, dass die Konfiguration nun in die <code class="filename">databases.xml</code> verschoben wurde. Das Beste daran ist, dass
jeder Modul-Entwickler nun einfach, ohne viel Code-Overhead, auf die Icinga-Datenbank zugreifen kann- also Adddon-Entwickler,
legt los!</p>
</td></tr>
</table></div>
<div class="important" title="Wichtig" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Wichtig]" src="../images/important.png"></td>
<th align="left">Wichtig</th>
</tr>
<tr><td align="left" valign="top">
<p>Das Folgende ist veraltet</p>
</td></tr>
</table></div>
<div class="section" title="11.3.1. Installation und Benutzung der Icinga API">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm139734663328496"></a>11.3.1. Installation und Benutzung der Icinga API</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
<p><span class="bold"><strong>Voraussetzungen</strong></span></p>
<p>Sie benötigen installierte und lauffähige 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="2.6. 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>
<div class="itemizedlist"><ul class="itemizedlist" type="circle">
<li class="listitem">
<p><span class="bold"><strong>RHEL/Fedora/CentOS</strong></span></p>
<p>Stellen Sie sicher, dass Sie ein Repository/Packages für PHP 5.2.x zur Verfügung haben - RHEL/CentOS (CentOS <= 5.4)
unterstützen lediglich 5.1.6.</p>
<pre class="programlisting"> # yum install php-pdo php-mysql|pgsql </pre>
</li>
<li class="listitem">
<p><span class="bold"><strong>Debian/Ubuntu</strong></span></p>
<pre class="programlisting"> # apt-get install php5 php5-mysql|pgsql </pre>
</li>
<li class="listitem">
<p><span class="bold"><strong>openSuSE;</strong></span></p>
<p>Bitte benutzen Sie yast zur Installation der Pakete php5, php5-pdo und php5-mysql bzw. php5-pgsql.</p>
</li>
</ul></div>
<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>
<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>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äßig in
/usr/local/icinga/share/icinga-api/ und Sie können diesen Abschnitt überspringen.</p>
</td></tr>
</table></div>
<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="6.5. Installation des 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 \
--with-web-user=www-data \
--with-web-group=www-data</pre>
<p> </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>Die --with-web...-Direktiven müssen gesetzt sein. Anderenfalls werden die Web-Logs nicht korrekt erstellt. Außerdem
kann dies zu einem leeren Haupt-Cronk führen. Bitte beachten Sie, dass die Werte von 'user' und 'group' abhängig von der
Distribution sind.</p>
</td></tr>
</table></div>
<p> </p>
<pre class="programlisting"> # make install</pre>
</li>
</ol></div>
</li></ul></div>
</div>
<div class="section" title="11.3.2. Konfiguration">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm139734663297056"></a>11.3.2. Konfiguration</h3></div></div></div>
<p>Wenn Sie Ihr eigenes Addon auf Basis der Icinga API entwickeln möchten, benötigen Sie das folgende assoziative
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>
</div>
<div class="section" title="11.3.3. Unterstützte Backends">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm139734663294176"></a>11.3.3. Unterstützte Backends</h3></div></div></div>
<p>Aktuell sind folgende Backend Typen verfügbar. Mehr Information finden Sie unter doc/icinga-api-types.txt.</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">
<p>IDOUtils DB - OK</p>
</li>
<li class="listitem">
<p>Livestatus Modul - experimentell, noch nicht produktiv einsetzbar.</p>
</li>
<li class="listitem">
<p>Dateibasierend, status.dat - experimentell, noch nicht produktiv einsetzbar.</p>
</li>
</ul></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>
<pre class="programlisting"> $apiRes = $api->createSearch()
->setSearchTarget(IcingaApi::TARGET_HOST)
->setResultColumns(array('HOST_NAME', 'HOST_CURRENT_STATE'))
->fetch();</pre>
<p>Mit Hilfe von setSearchFilter() können Sie Filter benutzen, um die Suche einzuschränken:</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>
</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>
<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>
</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="idm139734663274960"></a>
<a class="indexterm" name="idm139734663273712"></a>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="epnplugins.html">Zurück</a> </td>
<td width="20%" align="center"><a accesskey="u" href="ch11.html">Nach oben</a></td>
<td width="40%" align="right"> <a accesskey="n" href="icinga-web-api.html">Weiter</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">11.2. Entwickeln von Plugins für die Nutzung mit Embedded Perl </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Zum Anfang</a></td>
<td width="40%" align="right" valign="top"> 11.4. Die Icinga Web REST API</td>
</tr>
</table>
</div>
<P class="copyright">© 1999-2009 Ethan Galstad, 2009-2017 Icinga Development Team, https://www.icinga.com</P>
</body>
</html>
|