/[monit]/monit/http/cervlet.c
ViewVC logotype

Diff of /monit/http/cervlet.c

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

revision 1.88 by hauk, Wed Aug 27 22:45:07 2003 UTC revision 1.89 by hauk, Sun Aug 31 20:05:51 2003 UTC
# Line 86  static void do_home_device(HttpRequest, Line 86  static void do_home_device(HttpRequest,
86  static void do_home_directory(HttpRequest, HttpResponse);  static void do_home_directory(HttpRequest, HttpResponse);
87  static void do_home_file(HttpRequest, HttpResponse);  static void do_home_file(HttpRequest, HttpResponse);
88  static void do_home_process(HttpRequest, HttpResponse);  static void do_home_process(HttpRequest, HttpResponse);
89    static void do_home_remote(HttpRequest, HttpResponse);
90  static void do_about(HttpRequest, HttpResponse);  static void do_about(HttpRequest, HttpResponse);
91  static void not_found(HttpRequest, HttpResponse);  static void not_found(HttpRequest, HttpResponse);
92  static void do_runtime(HttpRequest, HttpResponse);  static void do_runtime(HttpRequest, HttpResponse);
# Line 98  static void do_service_device(HttpReques Line 99  static void do_service_device(HttpReques
99  static void do_service_directory(HttpRequest, HttpResponse, Service_T);  static void do_service_directory(HttpRequest, HttpResponse, Service_T);
100  static void do_service_file(HttpRequest, HttpResponse, Service_T);  static void do_service_file(HttpRequest, HttpResponse, Service_T);
101  static void do_service_process(HttpRequest, HttpResponse, Service_T);  static void do_service_process(HttpRequest, HttpResponse, Service_T);
102    static void do_service_host(HttpRequest, HttpResponse, Service_T);
103    
104  extern ssl_server_connection * mySSLServerConnection;  extern ssl_server_connection * mySSLServerConnection;
105    
# Line 226  static void do_home(HttpRequest req, Htt Line 228  static void do_home(HttpRequest req, Htt
228    do_home_device(req, res);    do_home_device(req, res);
229    do_home_file(req, res);    do_home_file(req, res);
230    do_home_directory(req, res);    do_home_directory(req, res);
231      do_home_remote(req, res);
232        
233    FOOT    FOOT
234                
# Line 541  static void do_service(HttpRequest req, Line 544  static void do_service(HttpRequest req,
544      switch (s->type) {      switch (s->type) {
545    
546      case TYPE_DEVICE:      case TYPE_DEVICE:
547        do_service_device(req, res, s);          do_service_device(req, res, s);
548        break;          break;
549            
550      case TYPE_DIRECTORY:      case TYPE_DIRECTORY:
551        do_service_directory(req, res, s);          do_service_directory(req, res, s);
552        break;          break;
553            
554      case TYPE_FILE:      case TYPE_FILE:
555        do_service_file(req, res, s);          do_service_file(req, res, s);
556        break;          break;
557            
558      case TYPE_PROCESS:      case TYPE_PROCESS:
559        do_service_process(req, res, s);          do_service_process(req, res, s);
560        break;          break;
561            
562        case TYPE_REMOTE:
563            do_service_host(req, res, s);
564            break;
565    
566      default:      default:
567        break;        break;
# Line 932  static void do_home_process(HttpRequest Line 939  static void do_home_process(HttpRequest
939            "<td align=\"right\"><h3><b>Uptime</b></h3></td>"            "<td align=\"right\"><h3><b>Uptime</b></h3></td>"
940            "<td align=\"right\"><h3><b>CPU</b></h3></td>"            "<td align=\"right\"><h3><b>CPU</b></h3></td>"
941            "<td align=\"right\"><h3><b>Memory</b></h3></td>"            "<td align=\"right\"><h3><b>Memory</b></h3></td>"
942            "</tr>"            "</tr>");
           "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");  
943    
944        } else {        } else {
945    
946          out_print(res,          out_print(res,
947              "<br><p>&nbsp;</p>"
948            "<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">"            "<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">"
949            "<tr>"            "<tr>"
950            "<td width=\"20%\"><h3><b>Service</b></h3></td>"            "<td width=\"20%\"><h3><b>Service</b></h3></td>"
951            "<td align=\"left\"><h3><b>Status</b></h3></td>"            "<td align=\"left\"><h3><b>Status</b></h3></td>"
952            "</tr>"            "</tr>");
           "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");  
953    
954        }        }
955    
# Line 1004  static void do_home_process(HttpRequest Line 1010  static void do_home_process(HttpRequest
1010            
1011    }    }
1012        
1013    out_print(res, "</table>");    if(!header)
1014          out_print(res, "</table>");
1015        
1016  }  }
1017    
# Line 1029  static void do_home_device(HttpRequest r Line 1036  static void do_home_device(HttpRequest r
1036                  "<td align=\"left\"><h3><b>Status</b></h3></td>"                  "<td align=\"left\"><h3><b>Status</b></h3></td>"
1037                  "<td align=\"right\"><h3><b>Space usage</b></h3></td>"                  "<td align=\"right\"><h3><b>Space usage</b></h3></td>"
1038                  "<td align=\"right\"><h3><b>Inodes usage</b></h3></td>"                  "<td align=\"right\"><h3><b>Inodes usage</b></h3></td>"
1039                  "</tr>"                  "</tr>");
                 "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"  
                 );  
1040                
1041        header= FALSE;        header= FALSE;
1042                
# Line 1070  static void do_home_device(HttpRequest r Line 1075  static void do_home_device(HttpRequest r
1075                    (float) 100 *                    (float) 100 *
1076                    (s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) /                    (s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) /
1077                    s->devinfo->f_blocks,                    s->devinfo->f_blocks,
1078                    (float) (s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) /                    (float)(s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal)
1079                    1048576 * s->devinfo->f_bsize,                    / 1048576 * s->devinfo->f_bsize,
1080                    (float) 100 * (s->devinfo->f_files - s->devinfo->f_filesfree)/                    (float) 100 * (s->devinfo->f_files - s->devinfo->f_filesfree)/
1081                    s->devinfo->f_files,                    s->devinfo->f_files,
1082                    s->devinfo->f_files - s->devinfo->f_filesfree);                    s->devinfo->f_files - s->devinfo->f_filesfree);
# Line 1106  static void do_home_device(HttpRequest r Line 1111  static void do_home_device(HttpRequest r
1111    
1112    }    }
1113        
1114    out_print(res, "</table>");    if(!header)
1115          out_print(res, "</table>");
1116        
1117  }  }
1118    
# Line 1134  static void do_home_file(HttpRequest req Line 1140  static void do_home_file(HttpRequest req
1140                  "<td align=\"right\"><h3><b>Permission</b></h3></td>"                  "<td align=\"right\"><h3><b>Permission</b></h3></td>"
1141                  "<td align=\"right\"><h3><b>UID</b></h3></td>"                  "<td align=\"right\"><h3><b>UID</b></h3></td>"
1142                  "<td align=\"right\"><h3><b>GID</b></h3></td>"                  "<td align=\"right\"><h3><b>GID</b></h3></td>"
1143                  "</tr>"                  "</tr>");
                 "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"  
                 );  
1144                
1145        header= FALSE;        header= FALSE;
1146                
# Line 1189  static void do_home_file(HttpRequest req Line 1193  static void do_home_file(HttpRequest req
1193            
1194    }    }
1195        
1196    out_print(res, "</table>");    if(!header)
1197          out_print(res, "</table>");
1198        
1199  }  }
1200    
# Line 1216  static void do_home_directory(HttpReques Line 1221  static void do_home_directory(HttpReques
1221                  "<td align=\"right\"><h3><b>Permission</b></h3></td>"                  "<td align=\"right\"><h3><b>Permission</b></h3></td>"
1222                  "<td align=\"right\"><h3><b>UID</b></h3></td>"                  "<td align=\"right\"><h3><b>UID</b></h3></td>"
1223                  "<td align=\"right\"><h3><b>GID</b></h3></td>"                  "<td align=\"right\"><h3><b>GID</b></h3></td>"
1224                  "</tr>"                  "</tr>");
                 "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>");  
1225                
1226        header= FALSE;        header= FALSE;
1227                
# Line 1267  static void do_home_directory(HttpReques Line 1271  static void do_home_directory(HttpReques
1271            
1272    }    }
1273        
1274    out_print(res, "</table>");    if(!header)
1275          out_print(res, "</table>");
1276        
1277  }  }
1278    
1279    
1280    static void do_home_remote(HttpRequest req, HttpResponse res) {
1281    
1282      Port_T port;
1283      Service_T s;
1284      int on= TRUE;
1285      int header= TRUE;
1286      
1287      for(s= servicelist; s; s= s->next) {
1288        
1289        if(s->type != TYPE_REMOTE) continue;
1290    
1291        if(header) {
1292          
1293          out_print(res,
1294                    "<br><p>&nbsp;</p>"
1295                    "<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">"
1296                    "<tr>"
1297                    "<td width=\"20%\"><h3><b>Host</b></h3></td>"
1298                    "<td align=\"left\"><h3><b>Status</b></h3></td>"
1299                    "<td align=\"right\"><h3><b>Protocol(s)</b></h3></td>"
1300                    "</tr>");
1301          
1302          header= FALSE;
1303          
1304        }
1305        
1306        out_print(res,
1307                  "<tr %s><td width=\"20%\"><a href='/%s'>%s</a></td>",
1308                  on?"bgcolor=\"#EFEFEF\"":"", s->name, s->name);
1309        
1310        {
1311          int available= TRUE;
1312          
1313          for(port= s->portlist; port; port= port->next) {
1314            if(!port->is_available) {
1315              available= FALSE;
1316              break;
1317            }
1318          }
1319          
1320          if(available) {
1321            out_print(res, "<td align=\"left\">"
1322                      "<font color='#00ff00'>available</font></td>"
1323                      "<td align=\"right\">");
1324            for(port= s->portlist; port; port= port->next) {
1325              if(port != s->portlist)
1326                  out_print(res, "&nbsp;&nbsp;<b>|</b>&nbsp;&nbsp;");
1327              out_print(res, "[%s] at port %d", port->protocol->name, port->port);
1328            }
1329            out_print(res, "</td>");
1330          } else {
1331            out_print(res, "<td align=\"left\">"
1332                      "<font color='#ff0000'>not available</font></td>"
1333                      "<td align=\"right\">[%s] at port %d</td>",
1334                      port->protocol->name, port->port);
1335          }
1336        }
1337        
1338        out_print(res, "</tr>");
1339        on= on?FALSE:TRUE;
1340        
1341      }
1342      
1343      if(!header)
1344          out_print(res, "</table>");
1345    
1346    }
1347    
1348    
1349  static void do_service_device(HttpRequest req, HttpResponse res, Service_T s) {  static void do_service_device(HttpRequest req, HttpResponse res, Service_T s) {
1350        
1351    struct stat stat_buf;    struct stat stat_buf;
1352        
1353    int state= ( DeviceInfo_Usage(s->devinfo, s->path) && stat(s->path, &stat_buf) == 0 );    int state= ( DeviceInfo_Usage(s->devinfo, s->path) &&
1354                   stat(s->path, &stat_buf) == 0 );
1355        
1356    out_print(res,    out_print(res,
1357              "<p><br><h3>Device status</h3><br>");              "<p><br><h3>Device status</h3><br>");
# Line 1546  static void do_service_device(HttpReques Line 1621  static void do_service_device(HttpReques
1621  }  }
1622    
1623    
1624  static void do_service_directory(HttpRequest req, HttpResponse res, Service_T s) {  static void do_service_directory(HttpRequest req,
1625                                     HttpResponse res, Service_T s) {
1626      
1627    struct stat stat_buf;    struct stat stat_buf;
1628    int state=((stat(s->path, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode));    int state=((stat(s->path, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode));
1629        
# Line 2295  static void do_service_process(HttpReque Line 2371  static void do_service_process(HttpReque
2371        
2372  }  }
2373    
2374    
2375    static void do_service_host(HttpRequest req, HttpResponse res, Service_T s) {
2376    
2377      Port_T port;
2378      int available= TRUE;
2379      
2380      for(port= s->portlist; port; port= port->next) {
2381        if(!port->is_available) {
2382          available= FALSE;
2383          break;
2384        }
2385      }
2386    
2387      out_print(res,
2388                "<p><br><h3>Host status</h3><br>");
2389      out_print(res,"<table cellspacing=0 cellpadding=3 border=1 width=\"90%\">"
2390                "<tr><td width=\"30%\"><b>Parameter</b></td>"
2391                "<td width=\"70%\"><b>Value</b></td></tr>");
2392      out_print(res,
2393                "<tr><td>Name</a></td><td>%s</td></tr>", s->name);
2394      out_print(res,
2395                "<tr><td>Group</a></td><td><font color='#0000ff'>%s</font>"
2396                "</td></tr>", s->group?s->group:"(not defined)");
2397      out_print(res,
2398                "<tr><td>Remote status</a></td><td>%s</td></tr>",
2399                available?"<font color='#00ff00'>Available</font>":
2400                "<font color='#ff0000'>Not available</font>");
2401      out_print(res,
2402                "<tr><td>Monitoring mode</a></td><td>%s</td></tr>",
2403                modenames[s->mode]);
2404      out_print(res,
2405                "<tr><td>Monitoring status</a></td><td><font color='#ff8800'>%s"
2406                "</font></td></tr>",
2407                statusnames[s->do_monitor]);
2408      if(s->start) {
2409        int i = 0;
2410        
2411        out_print(res, "<tr><td>Start program</a></td><td>");
2412        while(s->start->arg[i])
2413            out_print(res, "%s ", s->start->arg[i++]);
2414        printf("</td></tr>");
2415      }
2416      if(s->stop) {
2417        int i = 0;
2418        
2419        out_print(res, "<tr><td>Stop program</a></td><td>");
2420        while(s->stop->arg[i])
2421            out_print(res, "%s ", s->stop->arg[i++]);
2422        printf("</td></tr>");
2423      }
2424      {
2425        Dependant_T d;
2426        
2427        for(d= s->dependantlist; d; d= d->next) {
2428          if(d->dependant != NULL) {
2429            out_print(res,"<tr><td>Depends on service </a></td>"
2430                      "<td> <a href=%s> %s </a></td></tr>",
2431                      d->dependant, d->dependant);
2432          }
2433        }
2434      }
2435      {
2436        Port_T n;
2437        for(n= s->portlist; n; n= n->next) {
2438          if(n->family == AF_INET) {
2439            if(n->SSL.use_ssl) {
2440              out_print(res,
2441                        "<tr><td>Host:Port</a></td><td>%s:%d%s [%s via SSL]</td>"
2442                        "</tr>", n->hostname, n->port, n->request?n->request:"",
2443                        n->protocol->name);
2444              
2445              if(n->SSL.certmd5 != NULL) {
2446                out_print(res,
2447                  "<tr><td>Server certificate md5 sum</a></td><td>%s</td></tr>",
2448                          n->SSL.certmd5);
2449              }
2450            } else {
2451              out_print(res,
2452                        "<tr><td>Host:Port</a></td><td>%s:%d%s [%s]</td></tr>",
2453                        n->hostname, n->port, n->request?n->request:"",
2454                        n->protocol->name);
2455            }
2456          } else if(n->family == AF_UNIX) {
2457            out_print(res,
2458                      "<tr><td>Unix Socket</a></td><td>%s [%s]</td></tr>",
2459                      n->pathname, n->protocol->name);
2460          }
2461        }
2462      }
2463      out_print(res,
2464                "<tr><td>Check service</a></td><td>Every %d cycle</td></tr>",
2465                s->every?s->every:1);
2466      if(s->def_timeout) {
2467        out_print(res,
2468                  "<tr><td>Timeout</a></td><td>"
2469                  "Timeout if %d restart within %d cycles</td></tr>",
2470                  s->to_start, s->to_cycle);
2471      }
2472      {
2473        Mail_T r;
2474        for(r= s->maillist; r; r= r->next) {
2475          out_print(res,
2476                    "<tr bgcolor=\"#EFEFEF\"><td>"
2477                    "Alert mail to</a></td><td>%s</td></tr>",
2478                    r->to?r->to:"");
2479          out_print(res,
2480                    "<tr><td>Alert from</a></td><td>%s</td></tr>",
2481                    r->from?r->from:"(default)");
2482          out_print(res,
2483                    "<tr><td>Alert subject</a></td><td>%s</td></tr>",
2484                    r->subject?r->subject:"(default)");
2485          out_print(res,
2486                    "<tr><td>Alert message</a></td><td>%s</td></tr>",
2487                    r->message?r->message:"(default)");
2488          out_print(res,
2489                    "<tr><td>Alert on stop</a></td><td>%s</td></tr>",
2490                    IS_EVENT_SET(r->events, EVENT_STOP)?"yes":"no");
2491          out_print(res,
2492                    "<tr><td>Alert on restart</a></td><td>%s</td></tr>",
2493                    IS_EVENT_SET(r->events, EVENT_RESTART)?"yes":"no");
2494          out_print(res,
2495                    "<tr><td>Alert on timeout</a></td><td>%s</td></tr>",
2496                    IS_EVENT_SET(r->events, EVENT_TIMEOUT)?"yes":"no");
2497          out_print(res,
2498                    "<tr><td>Alert on connection</a></td><td>%s</td></tr>",
2499                    IS_EVENT_SET(r->events, EVENT_CONNECTION)?"yes":"no");
2500          out_print(res,
2501                    "<tr><td>Alert on unmonitor</a></td><td>%s</td></tr>",
2502                    IS_EVENT_SET(r->events, EVENT_UNMONITOR)?"yes":"no");
2503        }
2504      }
2505      out_print(res, "</table>");
2506      out_print(res, "<table cellspacing=16><tr nowrap><td><font size=+1>");
2507      /* Start program */
2508      if(s->start)
2509          out_print(res,
2510                    "<td><form method=GET action=/%s>"
2511                    "<input type=hidden value='start' name=action>"
2512                    "<input type=submit value='Start service' style='font-size: "
2513                    "12pt'></form></td>", s->name);
2514      /* Stop program */
2515      if(s->stop)
2516          out_print(res,
2517                    "<td><form method=GET action=/%s>"
2518                    "<input type=hidden value='stop' name=action>"
2519                    "<input type=submit value='Stop service' style='font-size: "
2520                    "12pt'></form></td>", s->name);
2521      /* Restart program */
2522      if(s->start && s->stop)
2523          out_print(res,
2524                    "<td><form method=GET action=/%s>"
2525                    "<input type=hidden value='restart' name=action>"
2526                    "<input type=submit value='Restart service' style='font-size: "
2527                    "12pt'></form></td>", s->name);
2528      /* (un)monitor */
2529      {
2530        char *action[]= {"monitor", "unmonitor"};
2531        char *lable[]= {"Enable monitoring", "Disable monitoring"};
2532        out_print(res,
2533                  "<td><form method=GET action=/%s>"
2534                  "<input type=hidden value='%s' name=action>"
2535                  "<input type=submit value='%s' style='font-size: 12pt'>"
2536                  "</form></td></tr></table>",
2537                  s->name, action[s->do_monitor], lable[s->do_monitor]);
2538      }
2539    
2540    }

Legend:
Removed from v.1.88  
changed lines
  Added in v.1.89

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