summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2005-12-02 22:28:06 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2005-12-02 22:28:06 (GMT)
commitec6d0db61c33e65a1c3e414b07638a55022dfbf6 (patch)
tree7c9d092636a8d76fb422392870e99860569717e3
parent01886efb2bc2500e4cd441d7d18f74cb817efd0c (diff)
downloadmonitoring-plugins-ec6d0db61c33e65a1c3e414b07638a55022dfbf6.tar.gz
Support for Nagios 1 and Nagios 2 status files (Gerhard Lausser - 1296242)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1294 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--THANKS.in1
-rw-r--r--doc/developer-guidelines.sgml30
-rw-r--r--plugins/check_nagios.c44
-rw-r--r--plugins/t/check_nagios.nagios1.status.log5
-rw-r--r--plugins/t/check_nagios.nagios2.status.dat127
-rw-r--r--plugins/t/check_nagios.t81
6 files changed, 257 insertions, 31 deletions
diff --git a/THANKS.in b/THANKS.in
index e527b64..fa61ddb 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -172,3 +172,4 @@ Bob Ingraham
172Hans Engelen 172Hans Engelen
173Rick Frey 173Rick Frey
174Serhan Kiymaz 174Serhan Kiymaz
175Gerhard Lausser
diff --git a/doc/developer-guidelines.sgml b/doc/developer-guidelines.sgml
index 193bc9b..433a302 100644
--- a/doc/developer-guidelines.sgml
+++ b/doc/developer-guidelines.sgml
@@ -86,7 +86,7 @@
86 86
87 <para>Output should be in the format:</para> 87 <para>Output should be in the format:</para>
88 <literallayout> 88 <literallayout>
89 METRIC STATUS: Information text 89 SERVICE STATUS: Information text
90 </literallayout> 90 </literallayout>
91 <para>However, note that this is not a requirement of the API, so you cannot depend on this 91 <para>However, note that this is not a requirement of the API, so you cannot depend on this
92 being an accurate reflection of the status of the service - the status should always 92 being an accurate reflection of the status of the service - the status should always
@@ -289,15 +289,10 @@
289 </section> 289 </section>
290 290
291 <section><title>Translations</title> 291 <section><title>Translations</title>
292 <para>If possible, use translation tools for all output. Currently, most of the core C plugins 292 <para>If possible, use translation tools for all output to respect the user's language
293 use gettext for translation. General guidelines are:</para> 293 settings. See <xref linkend="translations_developers"> for guidelines
294 294 for the core plugins.
295 <orderedlist> 295 </para>
296 <listitem><para>short help is not translated</para></listitem>
297 <listitem><para>long help has options in English language, but text translated</para></listitem>
298 <listitem><para>"Copyright" kept in English</para></listitem>
299 <listitem><para>copyright holder names kept in original text</para></listitem>
300 </orderedlist>
301 </section> 296 </section>
302</section> 297</section>
303 298
@@ -611,17 +606,24 @@
611update the THANKS.in file.</para> 606update the THANKS.in file.</para>
612 </section> 607 </section>
613 608
614 <section><title>Translations for developers</title> 609 <section id="translations_developers"><title>Translations for developers</title>
615 <para>To make the job easier for translators please follow these guidelines:</para> 610 <para>To make the job easier for translators, please follow these guidelines:</para>
616 <orderedlist> 611 <orderedlist>
617 <listitem><para> 612 <listitem><para>
618 before creating new strings, check the po/de.po file to see if a similar string 613 Before creating new strings, check the po/nagios-plugins.pot file to
614 see if a similar string
619 already exists 615 already exists
620 </para></listitem> 616 </para></listitem>
621 <listitem><para> 617 <listitem><para>
622 for help texts, break into individual options so that these can be reused 618 For help texts, break into individual options so that these can be reused
623 between plugins 619 between plugins
624 </para></listitem> 620 </para></listitem>
621 <listitem><para>Try to avoid linefeeds unless you are working on a block of text</para></listitem>
622 <listitem><para>Short help is not translated</para></listitem>
623 <listitem><para>Long help has options in English language, but text translated</para></listitem>
624 <listitem><para>"Copyright" kept in English</para></listitem>
625 <listitem><para>Copyright holder names kept in original text</para></listitem>
626 <listitem><para>Debugging output does not need to be translated</para></listitem>
625 </orderedlist> 627 </orderedlist>
626 </section> 628 </section>
627 629
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index ab9c877..45514f1 100644
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
@@ -85,22 +85,25 @@ main (int argc, char **argv)
85 /* open the status log */ 85 /* open the status log */
86 fp = fopen (status_log, "r"); 86 fp = fopen (status_log, "r");
87 if (fp == NULL) { 87 if (fp == NULL) {
88 printf (_("CRITICAL - Cannot open status log for reading!\n")); 88 die (STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Cannot open status log for reading!"));
89 return STATE_CRITICAL;
90 } 89 }
91 90
92 /* get the date/time of the last item updated in the log */ 91 /* get the date/time of the last item updated in the log */
93 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { 92 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
94 temp_ptr = strtok (input_buffer, "]"); 93 if ((temp_ptr = strstr (input_buffer, "created=")) != NULL) {
95 temp_entry_time = 94 temp_entry_time = strtoul (temp_ptr + 8, NULL, 10);
96 (temp_ptr == NULL) ? 0L : strtoul (temp_ptr + 1, NULL, 10);
97 if (temp_entry_time > latest_entry_time)
98 latest_entry_time = temp_entry_time; 95 latest_entry_time = temp_entry_time;
96 break;
97 } else if ((temp_ptr = strtok (input_buffer, "]")) != NULL) {
98 temp_entry_time = strtoul (temp_ptr + 1, NULL, 10);
99 if (temp_entry_time > latest_entry_time)
100 latest_entry_time = temp_entry_time;
101 }
99 } 102 }
100 fclose (fp); 103 fclose (fp);
101 104
102 if (verbose >= 2) 105 if (verbose >= 2)
103 printf(_("command: %s\n"), PS_COMMAND); 106 printf("command: %s\n", PS_COMMAND);
104 107
105 /* run the command to check for the Nagios process.. */ 108 /* run the command to check for the Nagios process.. */
106 if((result = np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0)) != 0) 109 if((result = np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0)) != 0)
@@ -146,22 +149,29 @@ main (int argc, char **argv)
146 alarm (0); 149 alarm (0);
147 150
148 if (proc_entries == 0) { 151 if (proc_entries == 0) {
149 printf (_("Could not locate a running Nagios process!\n")); 152 die (STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Could not locate a running Nagios process!"));
150 return STATE_CRITICAL;
151 } 153 }
152 154
153 result = STATE_OK; 155 if (latest_entry_time == 0L) {
156 die (STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Cannot parse Nagios log file for valid time"));
157 }
154 158
155 time (&current_time); 159 time (&current_time);
156 if ((int)(current_time - latest_entry_time) > (expire_minutes * 60)) 160 if ((int)(current_time - latest_entry_time) > (expire_minutes * 60)) {
157 result = STATE_WARNING; 161 result = STATE_WARNING;
162 } else {
163 result = STATE_OK;
164 }
158 165
159 printf 166 printf ("NAGIOS %s: ", (result == STATE_OK) ? _("OK") : _("WARNING"));
160 (_("Nagios %s: located %d process%s, status log updated %d second%s ago\n"), 167 printf (ngettext ("%d process", "%d processes", proc_entries), proc_entries);
161 (result == STATE_OK) ? "ok" : "problem", proc_entries, 168 printf (", ");
162 (proc_entries == 1) ? "" : "es", 169 printf (
163 (int) (current_time - latest_entry_time), 170 ngettext ("status log updated %d second ago",
164 ((int) (current_time - latest_entry_time) == 1) ? "" : "s"); 171 "status log updated %d seconds ago",
172 (int) (current_time - latest_entry_time) ),
173 (int) (current_time - latest_entry_time) );
174 printf ("\n");
165 175
166 return result; 176 return result;
167} 177}
diff --git a/plugins/t/check_nagios.nagios1.status.log b/plugins/t/check_nagios.nagios1.status.log
new file mode 100644
index 0000000..64d9ce7
--- /dev/null
+++ b/plugins/t/check_nagios.nagios1.status.log
@@ -0,0 +1,5 @@
1# Nagios 1.2 Status File
2[1133537544] PROGRAM;1133537484;21980;1;1133537534;0;1;1;1;1;0;1;1;1
3[1133537544] HOST;ADSL;PENDING;0;0;0;0;0;0;0;0;1;1;1;1;0;0.0;0;1;1;(Not enough data to determine host status yet)
4[1133537544] HOST;Internet;UP;1133537486;1132135282;0;1402203;0;0;0;0;1;1;1;1;0;0.00;0;1;1;(Host assumed to be up)
5[1133537544] SERVICE;Internet;TCP/IP;OK;1/3;HARD;1133537486;1133537786;ACTIVE;1;1;1;1132135282;0;OK;1402203;0;0;0;0;0;1;0;4;1;0;0.00;0;1;1;0;PING OK - Packet loss = 0%, RTA = 0.09 ms
diff --git a/plugins/t/check_nagios.nagios2.status.dat b/plugins/t/check_nagios.nagios2.status.dat
new file mode 100644
index 0000000..6f62bac
--- /dev/null
+++ b/plugins/t/check_nagios.nagios2.status.dat
@@ -0,0 +1,127 @@
1########################################
2# NAGIOS STATUS FILE
3#
4# THIS FILE IS AUTOMATICALLY GENERATED
5# BY NAGIOS. DO NOT MODIFY THIS FILE!
6########################################
7
8info {
9 created=1133537302
10 version=2.0b5
11 }
12
13program {
14 modified_host_attributes=0
15 modified_service_attributes=0
16 nagios_pid=2750
17 daemon_mode=1
18 program_start=1133537167
19 last_command_check=1133537297
20 last_log_rotation=0
21 enable_notifications=1
22 active_service_checks_enabled=1
23 passive_service_checks_enabled=1
24 active_host_checks_enabled=1
25 passive_host_checks_enabled=1
26 enable_event_handlers=1
27 obsess_over_services=0
28 obsess_over_hosts=0
29 check_service_freshness=1
30 check_host_freshness=0
31 enable_flap_detection=1
32 enable_failure_prediction=1
33 process_performance_data=0
34 global_host_event_handler=
35 global_service_event_handler=
36 }
37
38host {
39 host_name=ADSL-derby-office
40 modified_attributes=0
41 check_command=check_host_alive_ping
42 event_handler=
43 has_been_checked=0
44 should_be_scheduled=0
45 check_execution_time=0.000
46 check_latency=0.000
47 check_type=0
48 current_state=0
49 last_hard_state=0
50 plugin_output=
51 performance_data=
52 last_check=0
53 next_check=0
54 current_attempt=1
55 max_attempts=3
56 state_type=1
57 last_state_change=0
58 last_hard_state_change=0
59 last_time_up=0
60 last_time_down=0
61 last_time_unreachable=0
62 last_notification=0
63 next_notification=0
64 no_more_notifications=0
65 current_notification_number=0
66 notifications_enabled=1
67 problem_has_been_acknowledged=0
68 acknowledgement_type=0
69 active_checks_enabled=1
70 passive_checks_enabled=1
71 event_handler_enabled=1
72 flap_detection_enabled=1
73 failure_prediction_enabled=1
74 process_performance_data=1
75 obsess_over_host=1
76 last_update=1133537302
77 is_flapping=0
78 percent_state_change=0.00
79 scheduled_downtime_depth=0
80 }
81
82service {
83 host_name=ADSL-derby-office
84 service_description=TCP/IP
85 modified_attributes=0
86 check_command=host5_service23_check_ping
87 event_handler=
88 has_been_checked=0
89 should_be_scheduled=1
90 check_execution_time=0.000
91 check_latency=0.000
92 check_type=0
93 current_state=0
94 last_hard_state=0
95 current_attempt=1
96 max_attempts=3
97 state_type=1
98 last_state_change=0
99 last_hard_state_change=0
100 last_time_ok=0
101 last_time_warning=0
102 last_time_unknown=0
103 last_time_critical=0
104 plugin_output=(Service assumed to be ok)
105 performance_data=
106 last_check=0
107 next_check=1133537317
108 current_notification_number=0
109 last_notification=0
110 next_notification=0
111 no_more_notifications=0
112 notifications_enabled=0
113 active_checks_enabled=1
114 passive_checks_enabled=1
115 event_handler_enabled=1
116 problem_has_been_acknowledged=0
117 acknowledgement_type=0
118 flap_detection_enabled=1
119 failure_prediction_enabled=1
120 process_performance_data=1
121 obsess_over_service=0
122 last_update=1133537302
123 is_flapping=0
124 percent_state_change=0.00
125 scheduled_downtime_depth=0
126 }
127
diff --git a/plugins/t/check_nagios.t b/plugins/t/check_nagios.t
new file mode 100644
index 0000000..7722071
--- /dev/null
+++ b/plugins/t/check_nagios.t
@@ -0,0 +1,81 @@
1#! /usr/bin/perl -w -I ..
2#
3# check_nagios tests
4#
5# $Id$
6#
7
8use strict;
9use Test::More tests => 13;
10use NPTest;
11
12my $successOutput = '/^NAGIOS OK: /';
13my $warningOutput = '/^NAGIOS WARNING: /';
14my $failureOutput = '/^NAGIOS CRITICAL: /';
15
16my $nagios1 = "t/check_nagios.nagios1.status.log";
17my $nagios2 = "t/check_nagios.nagios2.status.dat";
18
19my $result;
20
21$result = NPTest->testCmd(
22 "./check_nagios -F $nagios1 -e 5 -C init"
23 );
24cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" );
25like ( $result->output, $warningOutput, "Output for warning correct" );
26
27my $now = time;
28# This substitution is dependant on the testcase
29system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
30
31$result = NPTest->testCmd(
32 "./check_nagios -F $nagios1.tmp -e 1 -C init"
33 );
34cmp_ok( $result->return_code, "==", 0, "Log up to date" );
35like ( $result->output, $successOutput, "Output for success correct" );
36
37my $later = $now - 61;
38system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
39
40$result = NPTest->testCmd(
41 "./check_nagios -F $nagios1.tmp -e 1 -C init"
42 );
43cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" );
44my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
45like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
46
47$result = NPTest->testCmd(
48 "./check_nagios -F $nagios1.tmp -e 5 -C unlikely_command_string"
49 );
50cmp_ok( $result->return_code, "==", 2, "Nagios command not found" );
51like ( $result->output, $failureOutput, "Output for failure correct" );
52
53$result = NPTest->testCmd(
54 "./check_nagios -F $nagios2 -e 5 -C init"
55 );
56cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" );
57
58$now = time;
59system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
60
61$result = NPTest->testCmd(
62 "./check_nagios -F $nagios2.tmp -e 1 -C init"
63 );
64cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" );
65
66$later = $now - 61;
67system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
68
69$result = NPTest->testCmd(
70 "./check_nagios -F $nagios2.tmp -e 1 -C init"
71 );
72cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" );
73($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
74like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
75
76$result = NPTest->testCmd(
77 "./check_nagios -F t/check_nagios.t -e 1 -C init"
78 );
79cmp_ok( $result->return_code, "==", 2, "Invalid log file" );
80
81