Re: [Nagios-devel] [PATCH] Macro for $LASTSERVICESTATE$ for Nagios

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

Re: [Nagios-devel] [PATCH] Macro for $LASTSERVICESTATE$ for Nagios

Post by Guest »

------=_Part_6131_4944411.1193865234521
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 10/31/07, Haydn Solomon wrote:
>
>
>
> On Oct 28, 2007 5:38 PM, Haydn Solomon wrote:
>
> >
> >
> > On 10/28/07, Ethan Galstad 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");

------=_Part_6131_4944411.1193865234521
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 10/31/07, Haydn Solomon <haydn.solomon@gmai

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked