[Nagios-checkins] SF.net SVN: nagios:[2067] nagioscore/trunk

ageric at users.sourceforge.net ageric at users.sourceforge.net
Fri Aug 17 12:02:54 UTC 2012


Revision: 2067
          http://nagios.svn.sourceforge.net/nagios/?rev=2067&view=rev
Author:   ageric
Date:     2012-08-17 12:02:54 +0000 (Fri, 17 Aug 2012)
Log Message:
-----------
Add 'id' variable to first-class objects

First-class objects are timeperiod, command, contact, host, service,
escalations, dependencies and all kinds of groups.

This makes it trivial to do future object extensions without
breaking the object ABI, since we can now allocate arrays for
ancillary data and look up that data in constant-time without
even bothering with hashes. It's also extremely trivial to do
bitvector operations, allowing ridiculously fine-tuned
filtering.

The id variable will be recreated for each restart and is not
persistent. Persistent data should keep using uniquely identifying
strings (contact_name, host_name+service_description, etc) for
data that needs to be kept persistent.

As a nifty bonus, we keep the object count used to set the id
variables and thereby get an unambiguous object count of all
object types, and not only the ones that get scheduled.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/common/objects.c
    nagioscore/trunk/include/objects.h
    nagioscore/trunk/include/shared.h

Modified: nagioscore/trunk/common/objects.c
===================================================================
--- nagioscore/trunk/common/objects.c	2012-08-17 12:02:17 UTC (rev 2066)
+++ nagioscore/trunk/common/objects.c	2012-08-17 12:02:54 UTC (rev 2067)
@@ -57,6 +57,7 @@
 
 skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS];
 
+struct object_count num_objects;
 
 #ifdef NSCORE
 int __nagios_object_structure_version = CURRENT_OBJECT_STRUCTURE_VERSION;
@@ -457,6 +458,8 @@
 		timeperiod_list_tail = new_timeperiod;
 		}
 
+	new_timeperiod->id = num_objects.timeperiods++;
+
 	return new_timeperiod;
 	}
 
@@ -835,6 +838,8 @@
 		host_list_tail = new_host;
 		}
 
+	new_host->id = num_objects.hosts++;
+
 	return new_host;
 	}
 
@@ -1051,6 +1056,7 @@
 		hostgroup_list_tail = new_hostgroup;
 		}
 
+	new_hostgroup->id = num_objects.hostgroups++;
 	return new_hostgroup;
 	}
 
@@ -1179,6 +1185,7 @@
 		servicegroup_list_tail = new_servicegroup;
 		}
 
+	new_servicegroup->id = num_objects.servicegroups++;
 	return new_servicegroup;
 	}
 
@@ -1368,6 +1375,7 @@
 		contact_list_tail = new_contact;
 		}
 
+	new_contact->id = num_objects.contacts++;
 	return new_contact;
 	}
 
@@ -1508,6 +1516,7 @@
 		contactgroup_list_tail = new_contactgroup;
 		}
 
+	new_contactgroup->id = num_objects.contactgroups++;
 	return new_contactgroup;
 	}
 
@@ -1753,6 +1762,7 @@
 		service_list_tail = new_service;
 		}
 
+	new_service->id = num_objects.services++;
 	return new_service;
 	}
 
@@ -1865,6 +1875,7 @@
 		command_list_tail = new_command;
 		}
 
+	new_command->id = num_objects.commands++;
 	return new_command;
 	}
 
@@ -1940,6 +1951,7 @@
 		serviceescalation_list_tail = new_serviceescalation;
 		}
 
+	new_serviceescalation->id = num_objects.serviceescalations++;
 	return new_serviceescalation;
 	}
 
@@ -2067,6 +2079,7 @@
 		servicedependency_list_tail = new_servicedependency;
 		}
 
+	new_servicedependency->id = num_objects.servicedependencies++;
 	return new_servicedependency;
 	}
 
@@ -2139,6 +2152,7 @@
 		hostdependency_list_tail = new_hostdependency;
 		}
 
+	new_hostdependency->id = num_objects.hostdependencies++;
 	return new_hostdependency;
 	}
 
@@ -2210,6 +2224,7 @@
 		hostescalation_list_tail = new_hostescalation;
 		}
 
+	new_hostescalation->id = num_objects.hostescalations++;
 	return new_hostescalation;
 	}
 
@@ -3607,6 +3622,9 @@
 	/* free object skiplists */
 	free_object_skiplists();
 
+	/* we no longer have any objects */
+	memset(&num_objects, 0, sizeof(num_objects));
+
 	return OK;
 	}
 

Modified: nagioscore/trunk/include/objects.h
===================================================================
--- nagioscore/trunk/include/objects.h	2012-08-17 12:02:17 UTC (rev 2066)
+++ nagioscore/trunk/include/objects.h	2012-08-17 12:02:54 UTC (rev 2067)
@@ -34,7 +34,7 @@
 
 /*************** CURRENT OBJECT REVISION **************/
 
-#define CURRENT_OBJECT_STRUCTURE_VERSION        307     /* increment when changes are made to data structures... */
+#define CURRENT_OBJECT_STRUCTURE_VERSION        400     /* increment when changes are made to data structures... */
 /* Nagios 3 starts at 300, Nagios 4 at 400, etc. */
 
 
@@ -114,6 +114,7 @@
 
 /* TIMEPERIOD structure */
 typedef struct timeperiod_struct {
+	unsigned int id;
 	char    *name;
 	char    *alias;
 	timerange *days[7];
@@ -136,6 +137,7 @@
 
 /* CONTACTGROUP structure */
 typedef struct contactgroup_struct {
+	unsigned int id;
 	char	*group_name;
 	char    *alias;
 	contactsmember *members;
@@ -165,6 +167,7 @@
 
 /* COMMAND structure */
 typedef struct command_struct {
+	unsigned int id;
 	char    *name;
 	char    *command_line;
 	struct command_struct *next;
@@ -183,7 +186,8 @@
 
 
 /* CONTACT structure */
-	struct contact_struct {
+struct contact_struct {
+	unsigned int id;
 	char	*name;
 	char	*alias;
 	char	*email;
@@ -249,6 +253,7 @@
 
 /* HOSTGROUP structure */
 typedef struct hostgroup_struct {
+	unsigned int id;
 	char 	*group_name;
 	char    *alias;
 	hostsmember *members;
@@ -262,6 +267,7 @@
 
 /* HOST structure */
 struct host_struct {
+	unsigned int id;
 	char    *name;
 	char    *display_name;
 	char	*alias;
@@ -388,6 +394,7 @@
 
 /* SERVICEGROUP structure */
 typedef struct servicegroup_struct {
+	unsigned int id;
 	char 	*group_name;
 	char    *alias;
 	servicesmember *members;
@@ -401,6 +408,7 @@
 
 /* SERVICE structure */
 struct service_struct {
+	unsigned int id;
 	char	*host_name;
 	char	*description;
 	char    *display_name;
@@ -519,6 +527,7 @@
 
 /* SERVICE ESCALATION structure */
 typedef struct serviceescalation_struct {
+	unsigned int id;
 	char    *host_name;
 	char    *description;
 	int     first_notification;
@@ -542,6 +551,7 @@
 
 /* SERVICE DEPENDENCY structure */
 typedef struct servicedependency_struct {
+	unsigned int id;
 	int     dependency_type;
 	char    *dependent_host_name;
 	char    *dependent_service_description;
@@ -569,6 +579,7 @@
 
 /* HOST ESCALATION structure */
 typedef struct hostescalation_struct {
+	unsigned int id;
 	char    *host_name;
 	int     first_notification;
 	int     last_notification;
@@ -590,6 +601,7 @@
 
 /* HOST DEPENDENCY structure */
 typedef struct hostdependency_struct {
+	unsigned int id;
 	int     dependency_type;
 	char    *dependent_host_name;
 	char    *host_name;

Modified: nagioscore/trunk/include/shared.h
===================================================================
--- nagioscore/trunk/include/shared.h	2012-08-17 12:02:17 UTC (rev 2066)
+++ nagioscore/trunk/include/shared.h	2012-08-17 12:02:54 UTC (rev 2067)
@@ -17,6 +17,22 @@
 	void *mmap_buf;
 	} mmapfile;
 
+/* official count of first-class objects */
+struct object_count {
+	unsigned int commands;
+	unsigned int timeperiods;
+	unsigned int hosts;
+	unsigned int hostescalations;
+	unsigned int hostdependencies;
+	unsigned int services;
+	unsigned int serviceescalations;
+	unsigned int servicedependencies;
+	unsigned int contacts;
+	unsigned int contactgroups;
+	unsigned int hostgroups;
+	unsigned int servicegroups;
+	};
+
 /* only usable on compile-time initialized arrays, for obvious reasons */
 #define ARRAY_SIZE(ary) (sizeof(ary) / sizeof(ary[0]))
 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list