[PATCH] Macro for $LASTSERVICESTATE$ for Nagios 2.10
Haydn Solomon
haydn.solomon at gmail.com
Wed Oct 31 22:13:54 CET 2007
On 10/31/07, Haydn Solomon <haydn.solomon at gmail.com> wrote:
>
>
>
> On Oct 28, 2007 5:38 PM, Haydn Solomon <haydn.solomon at gmail.com > wrote:
>
> >
> >
> > On 10/28/07, Ethan Galstad <nagios at nagios.org > wrote:
> > >
> > > Whoah - I was about to answer "$LASTSERVICESTATE$" like Andreas as
> > > well,
> > > because it seems like that macro should have existed for ages. Alas,
> > > it
> > > hasn't, so it will be added to CVS shortly - along with
> > > $LASTSERVICESTATEID$, $LASTHOSTSTATE$, and $LASTHOSTSTATEID$.
> >
> >
After getting the $LASTSERVICESTATE$ working, I realized that what I really
wanted was the $STATETYPE$ macro which is already provided for. In any case,
I started adding these macros to 2.10. I will continue to send patches for
the other macros for review as I'm sure they will come in handy.
Regards
--- nagios.h.in.orig 2007-10-31 16:26: 22.000000000 -0400
+++ nagios.h.in 2007-10-31 16:27:03.000000000 -0400
@@ -49,7 +49,7 @@
#define MACRO_ENV_VAR_PREFIX "NAGIOS_"
-#define MACRO_X_COUNT 99 /* size of macro_x[] array */
+#define MACRO_X_COUNT 100 /* size of macro_x[] array */
#define MACRO_HOSTNAME 0
#define MACRO_HOSTALIAS 1
@@ -150,6 +150,7 @@
#define MACRO_PROCESSSTARTTIME 96
#define MACRO_HOSTCHECKTYPE 97
#define MACRO_SERVICECHECKTYPE 98
+#define MACRO_LASTSERVICESTATE 99
--- utils.c.orig 2007-04-30 17:22:32.000000000 -0400
+++ utils.c 2007-10-31 15:55:08.000000000 -0400
@@ -496,6 +496,21 @@
strcpy(macro_x[MACRO_SERVICESTATE],"UNKNOWN");
}
+ /* get the last service state */
+ if(macro_x[MACRO_LASTSERVICESTATE]!=NULL)
+ free(macro_x[MACRO_LASTSERVICESTATE]);
+ macro_x[MACRO_LASTSERVICESTATE]=(char *)malloc(MAX_STATE_LENGTH);
+ if(macro_x[MACRO_LASTSERVICESTATE]!=NULL){
+ if(svc->last_state==STATE_OK)
+ strcpy(macro_x[MACRO_LASTSERVICESTATE],"OK");
+ else if(svc->last_state==STATE_WARNING)
+ strcpy(macro_x[MACRO_LASTSERVICESTATE],"WARNING");
+ else if(svc->last_state==STATE_CRITICAL)
+ strcpy(macro_x[MACRO_LASTSERVICESTATE],"CRITICAL");
+ else
+ strcpy(macro_x[MACRO_LASTSERVICESTATE],"UNKNOWN");
+ }
+
/* get the service state id */
if(macro_x[MACRO_SERVICESTATEID]!=NULL)
free(macro_x[MACRO_SERVICESTATEID]);
@@ -1542,6 +1557,21 @@
}
}
+ /* get the last service state */
+ else if(!strcmp(macro,"LASTSERVICESTATE")){
+ macro_ondemand=(char *)malloc(MAX_STATE_LENGTH);
+ if(macro_ondemand!=NULL){
+ if(svc->last_state==STATE_OK)
+ strcpy(macro_ondemand,"OK");
+ else if(svc->last_state==STATE_WARNING)
+ strcpy(macro_ondemand,"WARNING");
+ else if(svc->last_state==STATE_CRITICAL)
+ strcpy(macro_ondemand,"CRITICAL");
+ else
+ strcpy(macro_ondemand,"UNKNOWN");
+ }
+ }
+
/* get the service state id */
else if(!strcmp(macro,"SERVICESTATEID")){
macro_ondemand=(char *)malloc(MAX_STATEID_LENGTH);
@@ -2309,6 +2339,7 @@
add_macrox_name(MACRO_TIMET,"TIMET");
add_macrox_name(MACRO_LASTHOSTCHECK,"LASTHOSTCHECK");
add_macrox_name(MACRO_LASTSERVICECHECK,"LASTSERVICECHECK");
+ add_macrox_name(MACRO_LASTSERVICESTATE,"LASTSERVICESTATE");
add_macrox_name(MACRO_LASTHOSTSTATECHANGE,"LASTHOSTSTATECHANGE");
add_macrox_name(MACRO_LASTSERVICESTATECHANGE,"LASTSERVICESTATECHANGE");
add_macrox_name(MACRO_HOSTOUTPUT,"HOSTOUTPUT");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20071031/eba9ec9d/attachment.html>
-------------- next part --------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel
More information about the Developers
mailing list