monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[monit-dev] [monit] r222 committed - [No log message]


From: monit
Subject: [monit-dev] [monit] r222 committed - [No log message]
Date: Mon, 23 Aug 2010 13:44:57 +0000

Revision: 222
Author: martin2812
Date: Mon Aug 23 06:44:07 2010
Log: [No log message]
http://code.google.com/p/monit/source/detail?r=222

Modified:
 /trunk/monitor.h
 /trunk/xml.c

=======================================
--- /trunk/monitor.h    Mon Jul 26 12:10:25 2010
+++ /trunk/monitor.h    Mon Aug 23 06:44:07 2010
@@ -139,6 +139,9 @@
 #define MODE_PASSIVE       1
 #define MODE_MANUAL        2

+#define MSGTYPE_STATUS     0
+#define MSGTYPE_EVENT      1
+
 #define OPERATOR_GREATER   0
 #define OPERATOR_LESS      1
 #define OPERATOR_EQUAL     2
=======================================
--- /trunk/xml.c        Tue Jun 29 06:24:41 2010
+++ /trunk/xml.c        Mon Aug 23 06:44:07 2010
@@ -67,9 +67,10 @@
/* -------------------------------------------------------------- Prototypes */


-static void document_head(Buffer_T *);
+static void document_head(Buffer_T *, int);
 static void document_foot(Buffer_T *);
 static void status_service(Service_T, Buffer_T *, short);
+static void status_servicegroup(ServiceGroup_T, Buffer_T *, short);
 static void status_event(Event_T, Buffer_T *);


@@ -87,16 +88,21 @@
 char *status_xml(Event_T E, short L) {
   Buffer_T  B;
   Service_T S;
+  ServiceGroup_T SG;

   memset(&B, 0, sizeof(Buffer_T));

-  document_head(&B);
-
-  if (E)
+
+  if (E) {
+    document_head(&B, MSGTYPE_EVENT);
     status_event(E, &B);
-  else
+  } else {
+    document_head(&B, MSGTYPE_STATUS);
     for (S = servicelist_conf; S; S = S->next_conf)
       status_service(S, &B, L);
+    for (SG = servicegrouplist; SG; SG = SG->next)
+      status_servicegroup(SG, &B, L);
+  }

   document_foot(&B);

@@ -112,15 +118,12 @@
  * Prints a document header into the given buffer.
  * @param B Buffer object
  */
-static void document_head(Buffer_T *B) {
+static void document_head(Buffer_T *B, int msgtype) {

   Util_stringbuffer(B,
    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
-   "<monit>"
+   "<monit id=\"%s\" incarnation=\"%lld\" version=\"%s\" msgtype=\"%d\">"
    "<server>"
-   "<id>%s</id>"
-   "<incarnation>%lld</incarnation>"
-   "<version>%s</version>"
    "<uptime>%ld</uptime>"
    "<poll>%d</poll>"
    "<startdelay>%d</startdelay>"
@@ -129,6 +132,7 @@
    Run.id,
    (long long)Run.incarnation,
    VERSION,
+   msgtype,
    (long)Util_getProcessUptime(Run.pidfile),
    Run.polltime,
    Run.startdelay,
@@ -196,37 +200,28 @@
  * @param L Status information level
  */
 static void status_service(Service_T S, Buffer_T *B, short L) {
-  ServiceGroup_T sg;
-  ServiceGroupMember_T sgm;
   Event_T E = S->eventlist;

   Util_stringbuffer(B,
-           "<service type=\"%d\">"
+           "<service name=\"%s\">"
            "<collected_sec>%ld</collected_sec>"
            "<collected_usec>%ld</collected_usec>"
-           "<name>%s</name>"
+           "<type>%d</type>"
            "<status>%llu</status>"
            "<status_hint>%llu</status_hint>"
            "<monitor>%d</monitor>"
            "<monitormode>%d</monitormode>"
            "<pendingaction>%d</pendingaction>",
-           S->type,
+           S->name ? S->name : "",
            S->collected.tv_sec,
            S->collected.tv_usec,
-           S->name ? S->name : "",
+           S->type,
            S->error,
            S->error_hint,
            S->monitor,
            S->mode,
            S->doaction);

-  Util_stringbuffer(B, "<groups>");
-  for (sg = servicegrouplist; sg; sg = sg->next)
-    for (sgm = sg->members; sgm; sgm = sgm->next)
-      if (S->name && ! strcasecmp(sgm->name, S->name))
-        Util_stringbuffer(B, "<name>%s</name>", sg->name);
-  Util_stringbuffer(B, "</groups>");
-
/* if the service is in error state, display first active error message to provide more details */
   while (E) {
if ((E->state == STATE_FAILED || E->state == STATE_CHANGED) && (S->error & E->id) && E->message) {
@@ -407,6 +402,22 @@
   }
   Util_stringbuffer(B, "</service>");
 }
+
+
+/**
+ * Prints a servicegroups into the given buffer.
+ * @param SG ServiceGroup object
+ * @param B Buffer object
+ * @param L Status information level
+ */
+static void status_servicegroup(ServiceGroup_T SG, Buffer_T *B, short L) {
+  ServiceGroupMember_T SGM;
+
+  Util_stringbuffer(B, "<servicegroup name=\"%s\">", SG->name);
+  for (SGM = SG->members; SGM; SGM = SGM->next)
+    Util_stringbuffer(B, "<service>%s</service>", SGM->name);
+  Util_stringbuffer(B, "</servicegroup>");
+}


 /**



reply via email to

[Prev in Thread] Current Thread [Next in Thread]