summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fbf1919)
raw | patch | inline | side by side (parent: fbf1919)
author | Florian Forster <sifnfors@informatik.stud.uni-erlangen.de> | |
Thu, 12 Jun 2008 09:44:23 +0000 (11:44 +0200) | ||
committer | Florian Forster <sifnfors@informatik.stud.uni-erlangen.de> | |
Thu, 12 Jun 2008 09:44:23 +0000 (11:44 +0200) |
The plan is to have arbitrary values attached to notifications that user
defined actions can use to get machine parseable values for building
own notification strings or the like.
For example, the threshold checking stuff will (in the near future) add
the current (offending) value as well as the threshold values themselves
to the notification, so that notifying plugins don't need to parse the
(freely formatted) notification string to get that information.
defined actions can use to get machine parseable values for building
own notification strings or the like.
For example, the threshold checking stuff will (in the near future) add
the current (offending) value as well as the threshold values themselves
to the notification, so that notifying plugins don't need to parse the
(freely formatted) notification string to get that information.
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 8844c3397fd333a79f7959b6a81fd77ae42a1b26..784024c11ed5c11a78aca799a69507b39c7f782c 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
return (ds);
} /* data_set_t *plugin_get_ds */
+
+int plugin_notification_meta_add (notification_t *n,
+ const char *name,
+ enum notification_meta_type_e type,
+ const void *value)
+{
+ notification_meta_t *meta;
+ notification_meta_t *tail;
+
+ if ((n == NULL) || (name == NULL) || (value == NULL))
+ {
+ ERROR ("plugin_notification_meta_add: A pointer is NULL!");
+ return (-1);
+ }
+
+ meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
+ if (meta == NULL)
+ {
+ ERROR ("plugin_notification_meta_add: malloc failed.");
+ return (-1);
+ }
+ memset (meta, 0, sizeof (notification_meta_t));
+
+ sstrncpy (meta->name, name, sizeof (meta->name));
+ meta->type = type;
+ meta->next = NULL;
+
+ switch (type)
+ {
+ case NM_TYPE_STRING:
+ {
+ meta->value_string = strdup ((const char *) value);
+ if (meta->value_string == NULL)
+ {
+ ERROR ("plugin_notification_meta_add: strdup failed.");
+ sfree (meta);
+ return (-1);
+ }
+ break;
+ }
+ case NM_TYPE_SIGNED_INT:
+ {
+ meta->value_signed_int = *((int64_t *) value);
+ break;
+ }
+ case NM_TYPE_UNSIGNED_INT:
+ {
+ meta->value_unsigned_int = *((uint64_t *) value);
+ break;
+ }
+ case NM_TYPE_DOUBLE:
+ {
+ meta->value_double = *((double *) value);
+ break;
+ }
+ case NM_TYPE_BOOLEAN:
+ {
+ meta->value_boolean = *((bool *) value);
+ break;
+ }
+ default:
+ {
+ ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
+ sfree (meta);
+ return (-1);
+ }
+ } /* switch (type) */
+
+ tail = n->meta;
+ while ((tail != NULL) && (tail->next != NULL))
+ tail = tail->next;
+
+ if (tail == NULL)
+ n->meta = meta;
+ else
+ tail->next = meta;
+
+ return (0);
+} /* int plugin_notification_meta_add */
+
+int plugin_notification_meta_free (notification_t *n)
+{
+ notification_meta_t *this;
+ notification_meta_t *next;
+
+ this = n->meta;
+ n->meta = NULL;
+ while (this != NULL)
+ {
+ next = this->next;
+
+ if (this->type == NM_TYPE_STRING)
+ {
+ sfree (this->value_string);
+ }
+ sfree (this);
+
+ this = next;
+ }
+
+ return (0);
+} /* int plugin_notification_meta_free */
diff --git a/src/plugin.h b/src/plugin.h
index e2de6fff05d7ee4ad76c48ea4a5b3aec5a62cf26..99b224358205f87193f5512cb9622fb4bf52752f 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
};
typedef struct data_set_s data_set_t;
+enum notification_meta_type_e
+{
+ NM_TYPE_STRING,
+ NM_TYPE_SIGNED_INT,
+ NM_TYPE_UNSIGNED_INT,
+ NM_TYPE_DOUBLE,
+ NM_TYPE_BOOLEAN
+};
+
+typedef struct notification_meta_s
+{
+ char name[DATA_MAX_NAME_LEN];
+ enum notification_meta_type_e type;
+ union
+ {
+ const char *value_string;
+ int64_t value_signed_int;
+ uint64_t value_unsigned_int;
+ double value_double;
+ bool value_boolean;
+ };
+ struct notification_meta_s *next;
+} notification_meta_t;
+
typedef struct notification_s
{
int severity;
char plugin_instance[DATA_MAX_NAME_LEN];
char type[DATA_MAX_NAME_LEN];
char type_instance[DATA_MAX_NAME_LEN];
+ notification_meta_t *meta;
} notification_t;
/*
const data_set_t *plugin_get_ds (const char *name);
+int plugin_notification_meta_add (notification_t *n,
+ const char *name,
+ enum notification_meta_type_e type,
+ const void *value);
+int plugin_notification_meta_free (notification_t *n);
+
#endif /* PLUGIN_H */