check_ping modify output

The Noob thenoob06 at gmail.com
Sat Nov 8 15:06:29 CET 2008


Hello,
Before your answer , I decided to do a perl script which can do what I want
for my job.
But I like your idea and I try to modify the actual source code of
check_ping
I am a total Noob in C/C++ but I try to do this  (based on check_ping
nagios-plugins-1.4.13).
It is sure Developers Masters in C/C++ will improve it.
I add three options:
-C for Critical Output Message
-W for Warning Output Message
-O for OK Output Message

I do some tests with my modified plugin check_ping:
Before:
[root at localhost plugins]# ./check_ping -H 127.0.0.1 -w 100.0,20% -c
500.0,60%  -p 2

PING OK - Packet loss = 0%, RTA = 0.07
ms|rta=0.066000ms;100.000000;500.000000;0.000000 pl=0%;20;60;0

After:
[root at localhost plugins]# ./check_ping -H 127.0.0.1 -w 100.0,20% -c
500.0,60%  -p 2 -O CUSTOM_MESSAGE_OK -C CUSTOM_MESSAGE_CRITICAL -W
WARNING_MESSAGE

CUSTOM_MESSAGE_OK|rta=0.103000ms;100.000000;500.000000;0.000000
pl=0%;20;60;0

Before:
[root at localhost plugins]# ./check_ping -H 128.0.0.1 -w 100.0,20% -c
500.0,60%  -p 2
PING CRITICAL - Packet loss =
100%|rta=500.000000ms;100.000000;500.000000;0.000000 pl=100%;20;60;0

After:
[root at localhost plugins]# ./check_ping -H 128.0.0.1 -w 100.0,20% -c
500.0,60%  -p 2 -O CUSTOM_MESSAGE_OK -C CUSTOM_MESSAGE_CRITICAL -W
WARNING_MESSAGE

CUSTOM_MESSAGE_CRITICAL|rta=500.000000ms;100.000000;500.000000;0.000000
pl=100%;20;60;0

Now for warning messages( tested with iptables which block some icmp
packets..):
[root at localhost plugins]# ./check_ping -H 192.168.0.4 -w 100.0,20% -c
500.0,60%  -p 10 -O CUSTOM_MESSAGE_OK -C CUSTOM_MESSAGE_CRITICAL -W
WARNING_MESSAGE

WARNING_MESSAGE|rta=1.212000ms;100.000000;500.000000;0.000000 pl=16%;20;60;0

I hope this script can help some of you.
You can found the diff at the end of my email.
Best Regards
TheNoob


74a75,77
> char *critical_output;
> char *ok_output;
> char *warning_output;
160,162c163,168
<         if (pl == 100)
<             printf (_("PING %s - %sPacket loss = %d%%"), state_text
(this_result), warn_text,
<                             pl);
---
>         if (pl == 100) {
>             if (critical_output != NULL)
>                 printf(_(critical_output));
>             else
>                 printf (_("PING %s - %sPacket loss = %d%%"), state_text
(this_result), warn_text,pl);
>         }
164c170,175
<             printf (_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"),
---
>             if ((ok_output != NULL) && (state_text (this_result) == "OK"))
>                 printf(_(ok_output));
>             else if ((warning_output != NULL) && (state_text (this_result)
== "WARNING"))
>                 printf(_(warning_output));
>             else
>                 printf (_("PING %s - %sPacket loss = %d%%, RTA = %2.2f
ms"),
221c232
<         c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts,
&option);
---
>         c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:C:O:W:", longopts,
&option);
289a301,309
>         case 'C':
>             critical_output=optarg;
>             break;
>         case 'O':
>             ok_output=optarg;
>             break;
>         case 'W':
>             warning_output=optarg;
>             break;
584a605,607
>   printf (" %s\n", "-C, Critical Output Message");
>   printf (" %s\n", "-O, OK Output Message");
>   printf (" %s\n", "-W, Warning Output Message");



2008/11/6 Hendrik BŠäcker <andurin at process-zero.de>

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Little OT but:
>
> Aaron Segura schrieb:
> > 1)       Get the source
> >
> > 2)       Modify
> >
> > 3)       Compile
> >
> > 4)       ….
> >
> > 5)       Profit!
> >
> >
> 6) Share it back with the community ;)
>
> If it's nice enough send a unified patch file to the nagiosplugs-devel
> list, may be it's going upstream?
>
> - -
> Hendrik
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (Darwin)
>
> iEYEARECAAYFAkkSle0ACgkQlI0PwfxLQjkmyQCfXx2rXlxkz8357NNLxuzASkM4
> c/wAoIN3Meno8l5Fnptki9S+tsEmWQW9
> =JaT7
> -----END PGP SIGNATURE-----
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-users
> ::: Please include Nagios version, plugin version (-v) and OS when
> reporting any issue.
> ::: Messages without supporting info will risk being sent to /dev/null
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20081108/81bd859f/attachment.html>
-------------- next part --------------
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null


More information about the Users mailing list