Service Macro for check interval

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
e.v.wieringen
Posts: 1
Joined: Thu Dec 05, 2013 7:58 am

Service Macro for check interval

Post by e.v.wieringen »

Idea: Make the service check interval available as a service macro, say SERVICECHECKINTERVAL

Reason: If you want to process performance data with external tools like rrdtool, you need to have access to the service check interval, to set the right STEP value on creating rrd files. To my knowledge, there currently is no way of exporting this information. Thays why I wrote the this patch , which makes the normal_check_interval available as a macro called SERVICECHECKINTERVAL. The patch is written for Nagios Core v 4.0.x.

Regards,

Erwin van Wieringen

patch for nagios 4.0.x:

Code: Select all

diff -rupN nagios-4.0.1/common/macros.c nagios-4.0.1p1/common/macros.c
--- nagios-4.0.1/common/macros.c	2013-10-16 01:36:42.000000000 +0200
+++ nagios-4.0.1p1/common/macros.c	2013-10-24 16:32:45.606351362 +0200
@@ -807,6 +807,7 @@ int grab_macrox_value_r(nagios_macros *m
 		case MACRO_LASTSERVICEPROBLEMID:
 		case MACRO_LASTSERVICESTATE:
 		case MACRO_LASTSERVICESTATEID:
+		case MACRO_SERVICECHECKINTERVAL:
 
 			/* use saved service pointer */
 			if(arg1 == NULL && arg2 == NULL) {
@@ -1953,6 +1954,9 @@ int grab_standard_service_macro_r(nagios
 		case MACRO_LASTSERVICESTATEID:
 			*output = (char *)mkstr("%d", temp_service->last_state);
 			break;
+		case MACRO_SERVICECHECKINTERVAL:
+			asprintf(output, "%.2f", temp_service->check_interval);
+			break;
 #endif
 		case MACRO_SERVICEISVOLATILE:
 			*output = (char *)mkstr("%d", temp_service->is_volatile);
@@ -2693,6 +2697,7 @@ int init_macrox_names(void) {
 	add_macrox_name(HOSTVALUE);
 	add_macrox_name(SERVICEVALUE);
 	add_macrox_name(PROBLEMVALUE);
+	add_macrox_name(SERVICECHECKINTERVAL);
 
 	return OK;
 	}
diff -rupN nagios-4.0.1/include/macros.h nagios-4.0.1p1/include/macros.h
--- nagios-4.0.1/include/macros.h	2013-10-16 01:36:42.000000000 +0200
+++ nagios-4.0.1p1/include/macros.h	2013-10-24 16:33:53.965202031 +0200
@@ -38,7 +38,7 @@
 
 #define MAX_USER_MACROS				256	/* maximum number of $USERx$ macros */
 
-#define MACRO_X_COUNT				156	/* size of macro_x[] array */
+#define MACRO_X_COUNT				157	/* size of macro_x[] array */
 
 NAGIOS_BEGIN_DECL
 
@@ -217,6 +217,7 @@ typedef struct nagios_macros nagios_macr
 #define MACRO_HOSTVALUE                         153
 #define MACRO_SERVICEVALUE                      154
 #define MACRO_PROBLEMVALUE                      155
+#define MACRO_SERVICECHECKINTERVAL		156
 
 
 /************* MACRO CLEANING OPTIONS *****************/
Attachments
nagios4-servicecheckinterval.patch.gz
Servicecheckinterval patch for nagios 4
(782 Bytes) Downloaded 508 times
Locked