monit-dev
[Top][All Lists]
Advanced

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

web gui, display services by group, patch


From: Matt Harrington
Subject: web gui, display services by group, patch
Date: Fri, 05 Aug 2005 17:45:55 -0400
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Hi All,

I have a patch for the http/cervlet.c file, allowing you to display services on the web gui by group. I like this because I can use monit to show users what machines in the processing pool are alive, without cluttering the list with the rest of the monitored stuff.

For example, I have a list of remote hosts in the group `pool'. To see all services in the group `pool', i can go to:
   http://server:port/pool_group

or
   http://server:port/server_group for a listing of my standalone servers

This may be useful for listing services and all of their associated monitored files on the same page.

This patch does not display a list of services to view, nor does it alter the "Home >" in the top left corner, these were not necessary functions, but could probably be added easily on top of my work.

This patch works on monit 4.5.1 (sorry if there is a cvs tree it should be patched against, but it is fairly generic). I had to make some slight changes to avoid code duplication. The display functions, such as do_home_process, do_home_file, etc... now are small wrappers around do_home_process_list which takes a Service_T argument specifying a list of services to display. This was done so that do_group could call existing code with a pruned service list. I also abstracted a do_home_header so that do_group did not need a separate copy of the header printed by do_home .

The patch is in unified diff form and can be applied with:
   patch < cervlet.patch     # from within the monit-4.5.1/http directory

I tried to keep the code style consistant with the rest of the file. The patch contents are attached as I have no easy way to paste it into this message (sorry, special circumstances). If this is useful, I would like to see it, or similar functionality in the next version of monit.

Thanks,
Matt Harrington
--- cervlet.c.orig      2005-08-05 17:17:59.000000000 -0400
+++ cervlet.c   2005-08-05 17:15:33.000000000 -0400
@@ -88,13 +88,20 @@
 static void doGet(HttpRequest, HttpResponse);
 static void doPost(HttpRequest, HttpResponse);
 static void do_home(HttpRequest, HttpResponse);
+static void do_home_header(HttpResponse);
 static void do_home_system(HttpRequest, HttpResponse);
 static void do_home_device(HttpRequest, HttpResponse);
+static void do_home_device_list(HttpRequest, HttpResponse, Service_T);
 static void do_home_directory(HttpRequest, HttpResponse);
+static void do_home_directory_list(HttpRequest, HttpResponse, Service_T);
 static void do_home_file(HttpRequest, HttpResponse);
+static void do_home_file_list(HttpRequest, HttpResponse, Service_T);
 static void do_home_process(HttpRequest, HttpResponse);
+static void do_home_process_list(HttpRequest, HttpResponse, Service_T);
 static void do_home_host(HttpRequest, HttpResponse);
+static void do_home_host_list(HttpRequest, HttpResponse, Service_T);
 static void do_about(HttpRequest, HttpResponse);
+static void do_group(HttpRequest, HttpResponse, char*);
 static void not_found(HttpRequest, HttpResponse);
 static void do_runtime(HttpRequest, HttpResponse);
 static void do_viewlog(HttpRequest, HttpResponse);
@@ -242,11 +249,10 @@
   
 }
     
-
-static void do_home(HttpRequest req, HttpResponse res) {
+static void do_home_header(HttpResponse res) {
 
   char *uptime= Util_getUptime(Util_getProcessUptime(Run.pidfile), "&nbsp;");
- 
+
   HEAD("", Run.polltime)
   out_print(res,
     "<table cellspacing=\"0\" cellpadding=\"5\" width=\"100%%\" border=\"0\">"
@@ -265,6 +271,12 @@
     "</table>", Run.localhostname, uptime);
 
   FREE(uptime);
+
+}
+
+static void do_home(HttpRequest req, HttpResponse res) {
+
+  do_home_header(res);
   
   if(Run.doprocess) {
     do_home_system(req, res);
@@ -661,8 +673,18 @@
     }
 
   } else {
+    
+    // intercept group pages
+    char* name_ptr;
+    if ( ( name_ptr=strstr( name, "_group" ) ) != NULL )
+    {
+      *name_ptr='\0';
+      do_group(req, res, name);
+    }
 
-    not_found(req, res);
+    // guess it wasn't found
+    else
+      not_found(req, res);
 
   }
 
@@ -671,6 +693,54 @@
 
 }
 
+/* handle group paths */
+static void do_group(HttpRequest req, HttpResponse res, char* group) {
+
+  Service_T  s;
+  Service_T  services;
+  Service_T  current;
+
+  do_home_header(res);
+
+  // services is a head element, not part of the list
+  NEW(services);
+  services -> next_conf = NULL;
+  current = services;
+
+
+  // generate a list of services in the group
+  for(s=servicelist_conf ; s; s= s->next_conf) {
+
+    if ( ( s->group == NULL ) || ( strcmp( s->group, group ) != 0 ) )
+      continue;
+
+    // stick the service after current and increment current
+    NEW(current->next_conf);
+    memcpy(current->next_conf, s, sizeof(*s));
+    current = current->next_conf;
+    current->next_conf = NULL; // sever the next link
+  }
+
+
+  // if no services were found...
+  if(current == services)
+    not_found(req, res);
+
+  // ahhh, services were found, good
+  else
+  {
+
+    do_home_process_list(req, res, services->next_conf);
+    do_home_device_list(req, res, services->next_conf);
+    do_home_file_list(req, res, services->next_conf);
+    do_home_directory_list(req, res, services->next_conf);
+    do_home_host_list(req, res, services->next_conf);
+  }
+
+  FOOT
+
+}
+
 
 static void do_service(HttpRequest req, HttpResponse res, Service_T s) {
 
@@ -867,15 +937,17 @@
     
 }
 
-
 static void do_home_process(HttpRequest req, HttpResponse res) {
+  do_home_process_list(req, res, servicelist_conf);
+}
+
+static void do_home_process_list(HttpRequest req, HttpResponse res, Service_T 
s) {
 
-  Service_T      s;
   char          *status;
   int            on= TRUE;
   int            header= TRUE;
 
-  for(s= servicelist_conf; s; s= s->next_conf) {
+  for(; s; s= s->next_conf) {
     
     if(s->type != TYPE_PROCESS) continue;
     
@@ -956,13 +1028,16 @@
 
 
 static void do_home_device(HttpRequest req, HttpResponse res) {
+  do_home_device_list(req, res, servicelist_conf);
+}
+
+static void do_home_device_list(HttpRequest req, HttpResponse res, Service_T 
s) {
   
-  Service_T     s;
   char         *status;
   int           on= TRUE;
   int           header= TRUE;
   
-  for(s= servicelist_conf; s; s= s->next_conf) {
+  for(; s; s= s->next_conf) {
 
     if(s->type != TYPE_DEVICE) continue;
     
@@ -1033,15 +1108,17 @@
   
 }
 
-
 static void do_home_file(HttpRequest req, HttpResponse res) {
+  do_home_file_list(req, res, servicelist_conf);
+}
+
+static void do_home_file_list(HttpRequest req, HttpResponse res, Service_T s) {
   
-  Service_T  s;
   char      *status;
   int        on= TRUE;
   int        header= TRUE;
   
-  for(s= servicelist_conf; s; s= s->next_conf) {
+  for(; s; s= s->next_conf) {
     
     if(s->type != TYPE_FILE) continue;
     
@@ -1106,15 +1183,17 @@
   
 }
 
-
 static void do_home_directory(HttpRequest req, HttpResponse res) {
+  do_home_directory_list(req, res, servicelist_conf);
+}
+
+static void do_home_directory_list(HttpRequest req, HttpResponse res, 
Service_T s) {
   
-  Service_T        s;
   char            *status;
   int              on= TRUE;
   int              header= TRUE;
   
-  for(s= servicelist_conf; s; s= s->next_conf) {
+  for(; s; s= s->next_conf) {
     
     if(s->type != TYPE_DIRECTORY) continue;
 
@@ -1177,15 +1256,18 @@
 
 
 static void do_home_host(HttpRequest req, HttpResponse res) {
+  do_home_host_list(req, res, servicelist_conf);
+}
+
+static void do_home_host_list(HttpRequest req, HttpResponse res, Service_T s) {
 
-  Service_T  s;
   Icmp_T     icmp;
   Port_T     port;
   char      *status;
   int        on= TRUE;
   int        header= TRUE;
   
-  for(s= servicelist_conf; s; s= s->next_conf) {
+  for(; s; s= s->next_conf) {
 
     if(s->type != TYPE_HOST) continue;
 

reply via email to

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