summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 01886ef)
raw | patch | inline | side by side (parent: 01886ef)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 2 Dec 2005 22:28:06 +0000 (22:28 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 2 Dec 2005 22:28:06 +0000 (22:28 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1294 f882894a-f735-0410-b71e-b25c423dba1c
THANKS.in | patch | blob | history | |
doc/developer-guidelines.sgml | patch | blob | history | |
plugins/check_nagios.c | patch | blob | history | |
plugins/t/check_nagios.nagios1.status.log | [new file with mode: 0644] | patch | blob |
plugins/t/check_nagios.nagios2.status.dat | [new file with mode: 0644] | patch | blob |
plugins/t/check_nagios.t | [new file with mode: 0644] | patch | blob |
diff --git a/THANKS.in b/THANKS.in
index e527b6409137671ce61d5c415a91dd589adf40f7..fa61ddb4f54b5ffdab92af88754a63510aeb4c7c 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
Hans Engelen
Rick Frey
Serhan Kiymaz
+Gerhard Lausser
index 193bc9bed1e24797671717de62cf0f9f14eecbc0..433a3022b1a1f7bde4e0e66fdfa5f25aff40c4d6 100644 (file)
<para>Output should be in the format:</para>
<literallayout>
- METRIC STATUS: Information text
+ SERVICE STATUS: Information text
</literallayout>
<para>However, note that this is not a requirement of the API, so you cannot depend on this
being an accurate reflection of the status of the service - the status should always
</section>
<section><title>Translations</title>
- <para>If possible, use translation tools for all output. Currently, most of the core C plugins
- use gettext for translation. General guidelines are:</para>
-
- <orderedlist>
- <listitem><para>short help is not translated</para></listitem>
- <listitem><para>long help has options in English language, but text translated</para></listitem>
- <listitem><para>"Copyright" kept in English</para></listitem>
- <listitem><para>copyright holder names kept in original text</para></listitem>
- </orderedlist>
+ <para>If possible, use translation tools for all output to respect the user's language
+ settings. See <xref linkend="translations_developers"> for guidelines
+ for the core plugins.
+ </para>
</section>
</section>
update the THANKS.in file.</para>
</section>
- <section><title>Translations for developers</title>
- <para>To make the job easier for translators please follow these guidelines:</para>
+ <section id="translations_developers"><title>Translations for developers</title>
+ <para>To make the job easier for translators, please follow these guidelines:</para>
<orderedlist>
<listitem><para>
- before creating new strings, check the po/de.po file to see if a similar string
+ Before creating new strings, check the po/nagios-plugins.pot file to
+ see if a similar string
already exists
</para></listitem>
<listitem><para>
- for help texts, break into individual options so that these can be reused
+ For help texts, break into individual options so that these can be reused
between plugins
</para></listitem>
+ <listitem><para>Try to avoid linefeeds unless you are working on a block of text</para></listitem>
+ <listitem><para>Short help is not translated</para></listitem>
+ <listitem><para>Long help has options in English language, but text translated</para></listitem>
+ <listitem><para>"Copyright" kept in English</para></listitem>
+ <listitem><para>Copyright holder names kept in original text</para></listitem>
+ <listitem><para>Debugging output does not need to be translated</para></listitem>
</orderedlist>
</section>
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index ab9c877b557a0aac3d57dca0a2699739a21c1e98..45514f1a98aaf4e370ae295bbfbeb2c38dbf0af1 100644 (file)
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
/* open the status log */
fp = fopen (status_log, "r");
if (fp == NULL) {
- printf (_("CRITICAL - Cannot open status log for reading!\n"));
- return STATE_CRITICAL;
+ die (STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Cannot open status log for reading!"));
}
/* get the date/time of the last item updated in the log */
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
- temp_ptr = strtok (input_buffer, "]");
- temp_entry_time =
- (temp_ptr == NULL) ? 0L : strtoul (temp_ptr + 1, NULL, 10);
- if (temp_entry_time > latest_entry_time)
+ if ((temp_ptr = strstr (input_buffer, "created=")) != NULL) {
+ temp_entry_time = strtoul (temp_ptr + 8, NULL, 10);
latest_entry_time = temp_entry_time;
+ break;
+ } else if ((temp_ptr = strtok (input_buffer, "]")) != NULL) {
+ temp_entry_time = strtoul (temp_ptr + 1, NULL, 10);
+ if (temp_entry_time > latest_entry_time)
+ latest_entry_time = temp_entry_time;
+ }
}
fclose (fp);
if (verbose >= 2)
- printf(_("command: %s\n"), PS_COMMAND);
+ printf("command: %s\n", PS_COMMAND);
/* run the command to check for the Nagios process.. */
if((result = np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0)) != 0)
alarm (0);
if (proc_entries == 0) {
- printf (_("Could not locate a running Nagios process!\n"));
- return STATE_CRITICAL;
+ die (STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Could not locate a running Nagios process!"));
}
- result = STATE_OK;
+ if (latest_entry_time == 0L) {
+ die (STATE_CRITICAL, "NAGIOS %s: %s\n", _("CRITICAL"), _("Cannot parse Nagios log file for valid time"));
+ }
time (¤t_time);
- if ((int)(current_time - latest_entry_time) > (expire_minutes * 60))
+ if ((int)(current_time - latest_entry_time) > (expire_minutes * 60)) {
result = STATE_WARNING;
+ } else {
+ result = STATE_OK;
+ }
- printf
- (_("Nagios %s: located %d process%s, status log updated %d second%s ago\n"),
- (result == STATE_OK) ? "ok" : "problem", proc_entries,
- (proc_entries == 1) ? "" : "es",
- (int) (current_time - latest_entry_time),
- ((int) (current_time - latest_entry_time) == 1) ? "" : "s");
+ printf ("NAGIOS %s: ", (result == STATE_OK) ? _("OK") : _("WARNING"));
+ printf (ngettext ("%d process", "%d processes", proc_entries), proc_entries);
+ printf (", ");
+ printf (
+ ngettext ("status log updated %d second ago",
+ "status log updated %d seconds ago",
+ (int) (current_time - latest_entry_time) ),
+ (int) (current_time - latest_entry_time) );
+ printf ("\n");
return result;
}
diff --git a/plugins/t/check_nagios.nagios1.status.log b/plugins/t/check_nagios.nagios1.status.log
--- /dev/null
@@ -0,0 +1,5 @@
+# Nagios 1.2 Status File
+[1133537544] PROGRAM;1133537484;21980;1;1133537534;0;1;1;1;1;0;1;1;1
+[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)
+[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)
+[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
--- /dev/null
@@ -0,0 +1,127 @@
+########################################
+# NAGIOS STATUS FILE
+#
+# THIS FILE IS AUTOMATICALLY GENERATED
+# BY NAGIOS. DO NOT MODIFY THIS FILE!
+########################################
+
+info {
+ created=1133537302
+ version=2.0b5
+ }
+
+program {
+ modified_host_attributes=0
+ modified_service_attributes=0
+ nagios_pid=2750
+ daemon_mode=1
+ program_start=1133537167
+ last_command_check=1133537297
+ last_log_rotation=0
+ enable_notifications=1
+ active_service_checks_enabled=1
+ passive_service_checks_enabled=1
+ active_host_checks_enabled=1
+ passive_host_checks_enabled=1
+ enable_event_handlers=1
+ obsess_over_services=0
+ obsess_over_hosts=0
+ check_service_freshness=1
+ check_host_freshness=0
+ enable_flap_detection=1
+ enable_failure_prediction=1
+ process_performance_data=0
+ global_host_event_handler=
+ global_service_event_handler=
+ }
+
+host {
+ host_name=ADSL-derby-office
+ modified_attributes=0
+ check_command=check_host_alive_ping
+ event_handler=
+ has_been_checked=0
+ should_be_scheduled=0
+ check_execution_time=0.000
+ check_latency=0.000
+ check_type=0
+ current_state=0
+ last_hard_state=0
+ plugin_output=
+ performance_data=
+ last_check=0
+ next_check=0
+ current_attempt=1
+ max_attempts=3
+ state_type=1
+ last_state_change=0
+ last_hard_state_change=0
+ last_time_up=0
+ last_time_down=0
+ last_time_unreachable=0
+ last_notification=0
+ next_notification=0
+ no_more_notifications=0
+ current_notification_number=0
+ notifications_enabled=1
+ problem_has_been_acknowledged=0
+ acknowledgement_type=0
+ active_checks_enabled=1
+ passive_checks_enabled=1
+ event_handler_enabled=1
+ flap_detection_enabled=1
+ failure_prediction_enabled=1
+ process_performance_data=1
+ obsess_over_host=1
+ last_update=1133537302
+ is_flapping=0
+ percent_state_change=0.00
+ scheduled_downtime_depth=0
+ }
+
+service {
+ host_name=ADSL-derby-office
+ service_description=TCP/IP
+ modified_attributes=0
+ check_command=host5_service23_check_ping
+ event_handler=
+ has_been_checked=0
+ should_be_scheduled=1
+ check_execution_time=0.000
+ check_latency=0.000
+ check_type=0
+ current_state=0
+ last_hard_state=0
+ current_attempt=1
+ max_attempts=3
+ state_type=1
+ last_state_change=0
+ last_hard_state_change=0
+ last_time_ok=0
+ last_time_warning=0
+ last_time_unknown=0
+ last_time_critical=0
+ plugin_output=(Service assumed to be ok)
+ performance_data=
+ last_check=0
+ next_check=1133537317
+ current_notification_number=0
+ last_notification=0
+ next_notification=0
+ no_more_notifications=0
+ notifications_enabled=0
+ active_checks_enabled=1
+ passive_checks_enabled=1
+ event_handler_enabled=1
+ problem_has_been_acknowledged=0
+ acknowledgement_type=0
+ flap_detection_enabled=1
+ failure_prediction_enabled=1
+ process_performance_data=1
+ obsess_over_service=0
+ last_update=1133537302
+ is_flapping=0
+ percent_state_change=0.00
+ scheduled_downtime_depth=0
+ }
+
diff --git a/plugins/t/check_nagios.t b/plugins/t/check_nagios.t
--- /dev/null
+++ b/plugins/t/check_nagios.t
@@ -0,0 +1,81 @@
+#! /usr/bin/perl -w -I ..
+#
+# check_nagios tests
+#
+# $Id$
+#
+
+use strict;
+use Test::More tests => 13;
+use NPTest;
+
+my $successOutput = '/^NAGIOS OK: /';
+my $warningOutput = '/^NAGIOS WARNING: /';
+my $failureOutput = '/^NAGIOS CRITICAL: /';
+
+my $nagios1 = "t/check_nagios.nagios1.status.log";
+my $nagios2 = "t/check_nagios.nagios2.status.dat";
+
+my $result;
+
+$result = NPTest->testCmd(
+ "./check_nagios -F $nagios1 -e 5 -C init"
+ );
+cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" );
+like ( $result->output, $warningOutput, "Output for warning correct" );
+
+my $now = time;
+# This substitution is dependant on the testcase
+system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
+
+$result = NPTest->testCmd(
+ "./check_nagios -F $nagios1.tmp -e 1 -C init"
+ );
+cmp_ok( $result->return_code, "==", 0, "Log up to date" );
+like ( $result->output, $successOutput, "Output for success correct" );
+
+my $later = $now - 61;
+system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
+
+$result = NPTest->testCmd(
+ "./check_nagios -F $nagios1.tmp -e 1 -C init"
+ );
+cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" );
+my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
+like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
+
+$result = NPTest->testCmd(
+ "./check_nagios -F $nagios1.tmp -e 5 -C unlikely_command_string"
+ );
+cmp_ok( $result->return_code, "==", 2, "Nagios command not found" );
+like ( $result->output, $failureOutput, "Output for failure correct" );
+
+$result = NPTest->testCmd(
+ "./check_nagios -F $nagios2 -e 5 -C init"
+ );
+cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" );
+
+$now = time;
+system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
+
+$result = NPTest->testCmd(
+ "./check_nagios -F $nagios2.tmp -e 1 -C init"
+ );
+cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" );
+
+$later = $now - 61;
+system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
+
+$result = NPTest->testCmd(
+ "./check_nagios -F $nagios2.tmp -e 1 -C init"
+ );
+cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" );
+($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
+like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
+
+$result = NPTest->testCmd(
+ "./check_nagios -F t/check_nagios.t -e 1 -C init"
+ );
+cmp_ok( $result->return_code, "==", 2, "Invalid log file" );
+
+