/[monit]/monit/xml.c
ViewVC logotype

Diff of /monit/xml.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by martinp, Tue Feb 15 19:49:26 2005 UTC revision 1.13 by martinp, Tue Apr 5 19:52:57 2005 UTC
# Line 73  typedef struct mybuffer { Line 73  typedef struct mybuffer {
73  static void document_head(Buffer_T *);  static void document_head(Buffer_T *);
74  static void document_foot(Buffer_T *);  static void document_foot(Buffer_T *);
75  static void status_system(Buffer_T *);  static void status_system(Buffer_T *);
76  static void status_service(Service_T, Buffer_T *);  static void status_service(Service_T, Buffer_T *, short);
77  static void status_event(Event_T, Buffer_T *);  static void status_event(Event_T, Buffer_T *);
78  static void buf_print(Buffer_T *, const char *, ...);  static void buf_print(Buffer_T *, const char *, ...);
79    
# Line 85  static void buf_print(Buffer_T *, const Line 85  static void buf_print(Buffer_T *, const
85   * Return XML formated message for event notification or general status   * Return XML formated message for event notification or general status
86   * of monitored services and resources.   * of monitored services and resources.
87   * @param E An event object or NULL for general status   * @param E An event object or NULL for general status
88     * @param L Status information level
89   * @return XML document or NULL in the case of error. The caller must free   * @return XML document or NULL in the case of error. The caller must free
90  *  the memory.  *  the memory.
91   */   */
92  char *status_xml(Event_T E) {  char *status_xml(Event_T E, short L) {
93    
94    Buffer_T  B;    Buffer_T  B;
95    Service_T S;    Service_T S;
# Line 99  char *status_xml(Event_T E) { Line 100  char *status_xml(Event_T E) {
100    
101    if(E)    if(E)
102    {    {
103        /* there is no use for status level in the event (at least now) */
104      status_event(E, &B);      status_event(E, &B);
105    }    }
106    else    else
107    {    {
108      if(Run.doprocess) {      if(Run.doprocess) {
109          /* there is no use for status level in system status (at least now) */
110        status_system(&B);        status_system(&B);
111      }      }
112      for(S = servicelist_conf; S; S = S->next_conf)      for(S = servicelist_conf; S; S = S->next_conf)
113      {      {
114        status_service(S, &B);        status_service(S, &B, L);
115      }      }
116    }    }
117    document_foot(&B);    document_foot(&B);
# Line 200  static void status_system(Buffer_T *B) { Line 203  static void status_system(Buffer_T *B) {
203   * Prints a service status into the given buffer.   * Prints a service status into the given buffer.
204   * @param S Service object   * @param S Service object
205   * @param B Buffer object   * @param B Buffer object
206     * @param L Status information level
207   */   */
208  static void status_service(Service_T S, Buffer_T *B) {  static void status_service(Service_T S, Buffer_T *B, short L) {
209    buf_print(B,    buf_print(B,
210              "\t<service type=\"%d\">\r\n"              "\t<service type=\"%d\">\r\n"
211              "\t\t<collected>%ld</collected>\r\n"              "\t\t<collected>%ld</collected>\r\n"
# Line 215  static void status_service(Service_T S, Line 219  static void status_service(Service_T S,
219              S->error,              S->error,
220              S->monitor,              S->monitor,
221              S->group?S->group:"");              S->group?S->group:"");
222    if(Util_hasServiceStatus(S)) {    if(L == LEVEL_FULL)
223      if(S->type == TYPE_FILE ||    {
224         S->type == TYPE_DIRECTORY || S->type == TYPE_DEVICE) {      if(Util_hasServiceStatus(S)) {
225        buf_print(B,        if(S->type == TYPE_FILE ||
226                  "\t\t<mode>%o</mode>\r\n"           S->type == TYPE_DIRECTORY || S->type == TYPE_DEVICE) {
                 "\t\t<uid>%d</uid>\r\n"  
                 "\t\t<gid>%d</gid>\r\n",  
                 S->inf->st_mode & 07777,  
                 (int)S->inf->st_uid,  
                 (int)S->inf->st_gid);  
     }  
     if(S->type == TYPE_FILE || S->type == TYPE_DIRECTORY)  {  
       buf_print(B,  
                 "\t\t<timestamp>%ld</timestamp>\r\n",  
                 (long)S->inf->timestamp);  
     }  
     if(S->type == TYPE_FILE) {  
       buf_print(B,  
                 "\t\t<size>%lu</size>\r\n",  
                 (unsigned long) S->inf->st_size);  
       if(S->checksum) {  
227          buf_print(B,          buf_print(B,
228                    "\t\t<checksum type=\"%s\">%s</checksum>\r\n",                  "\t\t<mode>%o</mode>\r\n"
229                    checksumnames[S->checksum->type], S->inf->cs_sum);                  "\t\t<uid>%d</uid>\r\n"
230                    "\t\t<gid>%d</gid>\r\n",
231                    S->inf->st_mode & 07777,
232                    (int)S->inf->st_uid,
233                    (int)S->inf->st_gid);
234        }        }
235      }        if(S->type == TYPE_FILE || S->type == TYPE_DIRECTORY)  {
236      if(S->type == TYPE_DEVICE) {          buf_print(B,
237        buf_print(B,                  "\t\t<timestamp>%ld</timestamp>\r\n",
238                  "\t\t<block>\r\n"                  (long)S->inf->timestamp);
239                  "\t\t\t<size>%ld</size>\r\n"        }
240                  "\t\t\t<total>%ld</total>\r\n"        if(S->type == TYPE_FILE) {
241                  "\t\t\t<free>%ld</free>\r\n"          buf_print(B,
242                  "\t\t\t<freetotal>%ld</freetotal>\r\n"                  "\t\t<size>%lu</size>\r\n",
243                  "\t\t</block>\r\n",                  (unsigned long) S->inf->st_size);
244                  S->inf->f_bsize,          if(S->checksum) {
245                  S->inf->f_blocks,            buf_print(B,
246                  S->inf->f_blocksfree,                    "\t\t<checksum type=\"%s\">%s</checksum>\r\n",
247                  S->inf->f_blocksfreetotal);                    checksumnames[S->checksum->type], S->inf->cs_sum);
248        if(S->inf->f_files > 0) {          }
249          }
250          if(S->type == TYPE_DEVICE) {
251          buf_print(B,          buf_print(B,
252                    "\t\t<inode>\r\n"                  "\t\t<block>\r\n"
253                    "\t\t\t<size>%ld</size>\r\n"
254                    "\t\t\t<total>%ld</total>\r\n"
255                    "\t\t\t<free>%ld</free>\r\n"
256                    "\t\t\t<freetotal>%ld</freetotal>\r\n"
257                    "\t\t</block>\r\n",
258                    S->inf->f_bsize,
259                    S->inf->f_blocks,
260                    S->inf->f_blocksfree,
261                    S->inf->f_blocksfreetotal);
262            if(S->inf->f_files > 0) {
263              buf_print(B,
264                      "\t\t<inode>\r\n"
265                    "\t\t\t<total>%ld</total>\r\n"                    "\t\t\t<total>%ld</total>\r\n"
266                    "\t\t\t<free>%ld</free>\r\n"                    "\t\t\t<free>%ld</free>\r\n"
267                    "\t\t</inode>\r\n",                    "\t\t</inode>\r\n",
268                    S->inf->f_files,                    S->inf->f_files,
269                    S->inf->f_filesfree);                    S->inf->f_filesfree);
270            }
271        }        }
272      }        if(S->type == TYPE_PROCESS) {
     if(S->type == TYPE_PROCESS) {  
       buf_print(B,  
                 "\t\t<pid>%d</pid>\r\n"  
                 "\t\t<ppid>%d</ppid>\r\n"  
                 "\t\t<uptime>%ld</uptime>\r\n",  
                 S->inf->pid,  
                 S->inf->ppid,  
                 (long)S->inf->uptime);  
       if(Run.doprocess) {  
273          buf_print(B,          buf_print(B,
274                    "\t\t<children>%d</children>\r\n"                  "\t\t<pid>%d</pid>\r\n"
275                    "\t\t<memory>\r\n"                  "\t\t<ppid>%d</ppid>\r\n"
276                    "\t\t\t<kilobyte>%ld</kilobyte>\r\n"                  "\t\t<uptime>%ld</uptime>\r\n",
277                    "\t\t\t<kilobytetotal>%ld</kilobytetotal>\r\n"                  S->inf->pid,
278                    "\t\t\t<percent>%.1f</percent>\r\n"                  S->inf->ppid,
279                    "\t\t\t<percenttotal>%.1f</percenttotal>\r\n"                  (long)S->inf->uptime);
280                    "\t\t</memory>\r\n"          if(Run.doprocess) {
281                    "\t\t<cpu>\r\n"            buf_print(B,
282                      "\t\t<children>%d</children>\r\n"
283                      "\t\t<memory>\r\n"
284                      "\t\t\t<kilobyte>%ld</kilobyte>\r\n"
285                      "\t\t\t<kilobytetotal>%ld</kilobytetotal>\r\n"
286                      "\t\t\t<percent>%.1f</percent>\r\n"
287                      "\t\t\t<percenttotal>%.1f</percenttotal>\r\n"
288                      "\t\t</memory>\r\n"
289                      "\t\t<cpu>\r\n"
290                    "\t\t\t<percent>%.1f</percent>\r\n"                    "\t\t\t<percent>%.1f</percent>\r\n"
291                    "\t\t\t<percenttotal>%.1f</percenttotal>\r\n"                    "\t\t\t<percenttotal>%.1f</percenttotal>\r\n"
292                    "\t\t</cpu>\r\n",                    "\t\t</cpu>\r\n",
# Line 288  static void status_service(Service_T S, Line 294  static void status_service(Service_T S,
294                    S->inf->mem_kbyte,                    S->inf->mem_kbyte,
295                    S->inf->total_mem_kbyte,                    S->inf->total_mem_kbyte,
296                    S->inf->mem_percent/10.0,                    S->inf->mem_percent/10.0,
297                    S->inf->total_mem_percent/10.0,                    S->inf->total_mem_percent/10.0,
298                    S->inf->cpu_percent/10.0,                    S->inf->cpu_percent/10.0,
299                    S->inf->total_cpu_percent/10.0);                    S->inf->total_cpu_percent/10.0);
300        }          }
     }  
     if(S->type == TYPE_HOST && S->icmplist) {  
       Icmp_T i;  
       for(i= S->icmplist; i; i= i->next) {  
         buf_print(B,  
                   "\t\t<icmp>\r\n"  
                   "\t\t\t<type>%s</type>\r\n"  
                   "\t\t\t<responsetime>%.3f</responsetime>\r\n"  
                   "\t\t</icmp>\r\n",  
                   icmpnames[i->type],  
                   i->is_available?i->response:-1.);  
301        }        }
302      }        if(S->type == TYPE_HOST && S->icmplist) {
303      if((S->type == TYPE_HOST || S->type == TYPE_PROCESS) && S-> portlist) {          Icmp_T i;
304        Port_T p;          for(i= S->icmplist; i; i= i->next) {
       for(p= S->portlist; p; p= p->next) {  
         if(p->family == AF_INET) {  
305            buf_print(B,            buf_print(B,
306                      "\t\t<port>\r\n"                    "\t\t<icmp>\r\n"
307                      "\t\t\t<hostname>%s</hostname>\r\n"                    "\t\t\t<type>%s</type>\r\n"
308                      "\t\t\t<port>%d</port>\r\n"                    "\t\t\t<responsetime>%.3f</responsetime>\r\n"
309                      "\t\t\t<request>%s</request>\r\n"                    "\t\t</icmp>\r\n",
310                      "\t\t\t<ssl>%s</ssl>\r\n"                    icmpnames[i->type],
311                      "\t\t\t<protocol>%s</protocol>\r\n"                    i->is_available?i->response:-1.);
312                      "\t\t\t<responsetime>%.3f</responsetime>\r\n"          }
313                      "\t\t</port>\r\n",        }
314                      p->hostname,        if((S->type == TYPE_HOST || S->type == TYPE_PROCESS) && S-> portlist) {
315                      p->port,          Port_T p;
316                      p->request?p->request:"",          for(p= S->portlist; p; p= p->next) {
317                      p->SSL.use_ssl?"SSL":"",            if(p->family == AF_INET) {
318                      p->protocol->name,              buf_print(B,
319                      p->is_available?p->response:-1.);                      "\t\t<port>\r\n"
320                                  "\t\t\t<hostname>%s</hostname>\r\n"
321          } else if(p->family == AF_UNIX) {                      "\t\t\t<port>%d</port>\r\n"
322            buf_print(B,                      "\t\t\t<request>%s</request>\r\n"
323                      "\t\t<unix>\r\n"                      "\t\t\t<ssl>%s</ssl>\r\n"
324                        "\t\t\t<protocol>%s</protocol>\r\n"
325                        "\t\t\t<responsetime>%.3f</responsetime>\r\n"
326                        "\t\t</port>\r\n",
327                        p->hostname,
328                        p->port,
329                        p->request?p->request:"",
330                        p->SSL.use_ssl?"SSL":"",
331                        p->protocol->name,
332                        p->is_available?p->response:-1.);
333              
334              } else if(p->family == AF_UNIX) {
335                buf_print(B,
336                        "\t\t<unix>\r\n"
337                      "\t\t\t<path>%s</path>\r\n"                      "\t\t\t<path>%s</path>\r\n"
338                      "\t\t\t<protocol>%s</protocol>\r\n"                      "\t\t\t<protocol>%s</protocol>\r\n"
339                      "\t\t\t<responsetime>%.3f</responsetime>\r\n"                      "\t\t\t<responsetime>%.3f</responsetime>\r\n"
# Line 335  static void status_service(Service_T S, Line 341  static void status_service(Service_T S,
341                      p->pathname,                      p->pathname,
342                      p->protocol->name,                      p->protocol->name,
343                      p->is_available?p->response:-1.);                      p->is_available?p->response:-1.);
344              }
345          }          }
346        }        }
347      }      }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26