1 -- Authors: Raffaello Pelagalli <raffa@niah.org>
2 -- License: LGPL, version 2.1 or later
3 -- Last Changed: 2008-05-08
7 -- Made by Raffaello Pelagalli (raffa at niah.org)
9 -- Started on Sun Mar 9 00:22:31 2008 Raffaello Pelagalli
10 -- Last update Thu May 8 23:29:32 2008 Raffaello Pelagalli
12 -- This library is free software; you can redistribute it and/or
13 -- modify it under the terms of the GNU Lesser General Public
14 -- License as published by the Free Software Foundation; either
15 -- version 2.1 of the License, or (at your option) any later version.
17 -- This library is distributed in the hope that it will be useful,
18 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
19 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 -- Lesser General Public License for more details.
22 -- You should have received a copy of the GNU Lesser General Public
23 -- License along with this library; if not, write to the Free Software
24 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 -- Nagios checking script
29 -- Reports nagios status in ion status bar
30 -- Sample configuration:
31 -- mod_statusbar.launch_statusd{
35 -- "http://user1:password1@server1.domain1.tld/cgi-bin/nagios2/nginfo.pl",
36 -- "http://user2:password2@server2.domain2.tld/nagios/cgi-bin/nginfo.pl",
42 -- Need to be used with nginfo.pl script from
43 -- http://redstack.net/blog/index.php/2008/05/08/nagios-status-report-in-ion3-statusbar.html
49 local status
= {0, 0, 0, 0}
52 update_interval
=30*1000,
56 local settings
= table.join(statusd
.get_config("nginfo"), defaults
)
59 StartElement
= function (parser
, name
)
60 if (name
== "current_state") then
61 nginfo_callbacks
.CharacterData
= function (parser
, val
)
62 status
[tonumber(val
) + 1] =
63 status
[tonumber(val
) + 1] + 1
67 EndElement
= function (parser
, name
)
68 if (name
== "current_state") then
69 nginfo_callbacks
.CharacterData
= false
72 CharacterData
= false,
76 p
= lxp
.new(nginfo_callbacks
)
81 function get_nginfo ()
84 local http
= require("socket.http")
85 socket
.http
.TIMEOUT
=10
86 local errstr
= " ERROR while reading data"
87 for n
, url
in pairs(settings
.urls
) do
88 b
, c
, h
= http
.request(url
)
89 if not (c
== 200) then
91 errstr
= errstr
.. " (NET " .. tostring(c
) .. ")"
93 local st
, err
= pcall(parse
, b
)
96 errstr
= errstr
.. " (XML" .. err
.. ")"
104 return "OK: " .. tostring(status
[1])
105 .. ", WARN: " .. tostring(status
[2])
106 .. ", ERROR: " .. tostring(status
[3])
107 .. ", UNKN: " .. tostring(status
[4])
111 local function update_nginfo()
112 statusd
.inform("nginfo", get_nginfo())
113 if (status
[3] > 0 or status
[4] > 0) then
114 statusd
.inform("nginfo_hint", "critical")
115 elseif (status
[2] > 0) then
116 statusd
.inform("nginfo_hint", "important")
118 statusd
.inform("nginfo_hint", "normal")
120 ng_timer
:set(settings
.update_interval
, update_nginfo
)
124 ng_timer
=statusd
.create_timer()