File: icinga-api.html

package info (click to toggle)
icinga 1.0.2-2%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 33,952 kB
  • ctags: 13,294
  • sloc: xml: 154,821; ansic: 99,198; sh: 14,585; sql: 5,852; php: 5,126; perl: 2,838; makefile: 1,268
file content (231 lines) | stat: -rw-r--r-- 9,584 bytes parent folder | download | duplicates (2)
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Installation and use of the Icinga API</title>
<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.0.2 Documentation">
<link rel="up" href="ch10.html" title="Chapter 10. Development">
<link rel="prev" href="icinga-web-scratch.html" title="Installation of the Icinga Web Frontend">
<link rel="next" href="ch11.html" title="Chapter 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 and use of the Icinga API</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="icinga-web-scratch.html">Prev</a> </td>
<th width="60%" align="center">Chapter 10. Development</th>
<td width="20%" align="right"> <a accesskey="n" href="ch11.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section" title="Installation and use of the Icinga API">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="icinga-api"></a>Installation and use of the Icinga API</h2></div></div></div>
    

    <p><span class="bold"><strong>Prerequisites</strong></span></p>

    <p>You need Icinga Core and IDOUtils or <a class="link" href="http://mathias-kettner.de/checkmk_livestatus.html" target="_top">MKLiveStatus</a>
    installed and running in order to use the API.</p>

    <div class="note" title="Note" 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="[Note]" src="../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top">
        <p>If you don't have Icinga yet please follow the instructions given in the "<a class="link" href="quickstart-idoutils.html" title="Icinga with IDOUtils Quickstart">quickstart-idoutils</a>" documentation.</p>
    </td></tr>
</table></div>

    <p>If you are using IDOUtils database as data source, install PHP-PDO.</p>

    <p><span class="bold"><strong>RHEL/Fedora/CentOS</strong></span></p>

    <p>Make sure you have a repository/packages for PHP 5.2.x - RHEL/CentOS only support 5.1.6 out of the box.</p>

    <pre class="programlisting"># yum install php-pdo php-mysql|pgsql</pre>

    <p><span class="bold"><strong>Debian/Ubuntu</strong></span></p>

    <pre class="programlisting"># apt-get install php5 php5-mysql|pgsql</pre>

    <p><span class="bold"><strong>Installation and Configuration</strong></span></p>

    <div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
            <p><span class="bold"><strong>Download</strong></span></p>

            <p>Take your clone from the icinga-api.git to get a fresh branch</p>

            <pre class="programlisting"> # git clone git://git.icinga.org/icinga-api.git</pre>

            <p>or if you just need an update:</p>

            <pre class="programlisting"># cd icinga-api &amp;&amp; git pull origin master</pre>

            <p>or download the software using <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>Unpack Icinga API run configure and install it.</p>

            <pre class="programlisting"> # tar xzvf icinga-api-(version).tar.gz
 # ./configure</pre>
<p>You can set the prefix where it will be installed, and point Icinga API where your Icinga and IDOUtils config is located and which users are required to run (those settings are directly applied when installing the API through Icinga Core Installation).</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>

<pre class="programlisting"># make install</pre>

        </li>
<li class="listitem">
            <p><span class="bold"><strong>Configuration</strong></span></p>

            <p>If you are developing you own Addon based on the Icinga API, you need the following associative array.
</p>
<pre class="programlisting"> $idoConfig = array (
    'type'         =&gt; '&lt;Type of database&gt;',
    'host'         =&gt; '&lt;Database hostname&gt;', 
    'database'     =&gt; '&lt;Databasename&gt;',
    'user'         =&gt; '&lt;Username&gt;',
    'password'     =&gt; '&lt;password&gt;',
    'persistent'   =&gt; &lt;true | false&gt;,
    'table_prefix' =&gt; '&lt;table prefix&gt;', 
 );</pre>
<p> Example:</p>

            <pre class="programlisting"> $idoConfig = array (
    'type'         =&gt; 'mysql',
    'host'         =&gt; 'localhost',
    'database'     =&gt; 'ido',
    'user'         =&gt; 'idouser',
    'password'     =&gt; 'idopassword',
    'persistent'   =&gt; true,
    'table_prefix' =&gt; 'icinga_',
 );</pre>
        </li>
</ol></div>

    <p><span class="bold"><strong>Use of the API</strong></span></p>
<p>Examples can be found in doc/examples</p>

    <div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
            <p><span class="bold"><strong>Fetching data</strong></span></p>

            <p>hostnames and corresponding states</p>

            <p>Create an instance of class IcingaApi:</p>

            <pre class="programlisting"> $api = IcingaApi::getConnection(IcingaApi::CONNECTION_IDO, $idoConfig);</pre>
<p>Create your search:</p>

            <pre class="programlisting"> $apiRes = $api-&gt;createSearch()
 -&gt;setSearchTarget(IcingaApi::TARGET_HOST)
 -&gt;setResultColumns(array(’HOST_NAME’, ‘HOST_CURRENT_STATE’))
 -&gt;fetch();</pre>

            <p>By using setSearchFilter() you can define filters to narrow down the result set:</p>

            <pre class="programlisting"> $apiRes = $api-&gt;createSearch()
 -&gt;setSearchTarget(IcingaApi::TARGET_HOST)
 -&gt;setResultColumns(array(’HOST_NAME’, ‘HOST_CURRENT_STATE’))
 -&gt;setSearchFilter(HOST_NAME, ‘Switch%’, IcingaApi::MATCH_LIKE)
 -&gt;fetch();</pre>
        </li>
<li class="listitem">
            <p><span class="bold"><strong>Processing results</strong></span></p>

            <pre class="programlisting"> foreach($apiRes as $apiHandle){
    echo ‘Host ‘.$apiHandle-&gt;HOST_NAME.’ has state ‘.$apiHandle-&gt;HOST_CURRENT_STATE.’&lt;br /&gt;’;
 }</pre>
<p>Output without 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>Output with 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>Complete code without use of filters</strong></span></p>

            <pre class="programlisting"> &lt;?
 // Path to icinga api file
 $apiFile = ‘icinga-api/IcingaApi.php’;
 
 // Database connection
 $idoConfig = array (
    'type'         =&gt; 'mysql',
    'host'         =&gt; 'localhost',
    'database'     =&gt; 'ido',
    'user'         =&gt; 'idouser',
    'password'     =&gt; 'idopassword',
    'persistent'   =&gt; true,
    'table_prefix' =&gt; 'icinga_',
 );
 
 // Include required files
 require_once($apiFile);
 
 // Instance the class
 $api = IcingaApi::getConnection(IcingaApi::CONNECTION_IDO, $idoConfig);
 
 // Create search
 $apiRes = $api-&gt;createSearch()
 -&gt;setSearchTarget(IcingaApi::TARGET_HOST)
 -&gt;setResultColumns(array('HOST_NAME', 'HOST_CURRENT_STATE'))
 -&gt;fetch();
 
 // Create output
 foreach($apiRes as $apiHandle){
    echo 'Host '.$apiHandle-&gt;HOST_NAME.' has the current state '.$apiHandle-&gt;HOST_CURRENT_STATE.'&lt;br /&gt;';
 }
 ?&gt;</pre>

            <p>Please have a look at the <a class="link" href="http://git.icinga.org/" target="_top">git repository</a> for further information or consult the
            exmaples in the doc/examples folder.</p>
        </li>
</ol></div>

    <a class="indexterm" name="id2011013"></a>

    <a class="indexterm" name="id2011029"></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">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="ch10.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="ch11.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Installation of the Icinga Web Frontend </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Chapter 11. IDOUtils</td>
</tr>
</table>
</div>
<P class="copyright">© 2009-2010 Icinga Development Team, http://www.icinga.org</P>
</body>
</html>