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

Diff of /monit/status.c

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

revision 1.27 by hauk, Mon Jun 16 22:06:15 2003 UTC revision 1.28 by hauk, Tue Jun 17 02:04:57 2003 UTC
# Line 41  Line 41 
41  #endif  #endif
42    
43  #include "net.h"  #include "net.h"
44    #include "socket.h"
45  #include "monitor.h"  #include "monitor.h"
46  #include "monit_process.h"  #include "monit_process.h"
47  #include "ssl.h"  
48    
49    
50  /* Private Prototypes */  /* Private Prototypes */
51  static void local_status(Service_T);  static void local_status(Service_T);
52  static int remote_status(Service_T, ssl_connection *);  static int remote_status(Service_T);
53    
54  /**  /**
55   *  Print the status of services in the service list.   *  Print the status of services in the service list.
# Line 71  void status() { Line 72  void status() {
72    
73    Service_T s;    Service_T s;
74    int remote= TRUE;    int remote= TRUE;
   ssl_connection *ssl= NULL;  
75    char *uptime= get_process_uptime(Run.pidfile);    char *uptime= get_process_uptime(Run.pidfile);
76    
   if(Run.httpdssl) {  
   
     ssl= new_ssl_connection(Run.httpsslpem, SSL_VERSION_AUTO);  
   
   }  
   
77    fprintf(stdout, "monit daemon uptime: %s\n", uptime);    fprintf(stdout, "monit daemon uptime: %s\n", uptime);
78    free(uptime);    free(uptime);
79        
# Line 87  void status() { Line 81  void status() {
81    
82      if(remote) {      if(remote) {
83    
84        remote= remote_status(s, ssl);        remote= remote_status(s);
85                
86      } else {      } else {
87                
# Line 97  void status() { Line 91  void status() {
91            
92    }    }
93    
   if(Run.httpdssl) {  
   
     delete_ssl_socket(ssl);  
   
   }  
     
94  }  }
95    
96  /**  /**
# Line 113  void status_group(char *G) { Line 101  void status_group(char *G) {
101    
102    Service_T s;    Service_T s;
103    int remote= TRUE;    int remote= TRUE;
   ssl_connection *ssl= NULL;  
104    
105    ASSERT(G);    ASSERT(G);
106        
   if(Run.httpdssl) {  
   
     ssl= new_ssl_connection(Run.httpsslclientpem, SSL_VERSION_AUTO);  
   
   }  
   
107    for(s= servicelist; s; s= s->next) {    for(s= servicelist; s; s= s->next) {
108    
109      if(IS(s->group, G)) {      if(IS(s->group, G)) {
110                
111        if(remote) {        if(remote) {
112                    
113          remote= remote_status(s, ssl);          remote= remote_status(s);
114    
115        } else {        } else {
116                    
# Line 140  void status_group(char *G) { Line 121  void status_group(char *G) {
121      }      }
122            
123    }    }
   
   if(Run.httpdssl) {  
       
     delete_ssl_socket(ssl);  
       
   }  
124        
125  }  }
126    
# Line 262  static void local_status(Service_T s) { Line 237  static void local_status(Service_T s) {
237   * @param p  A Service_T object   * @param p  A Service_T object
238   * @return TRUE if the monit server could be connected   * @return TRUE if the monit server could be connected
239   */   */
240  static int remote_status(Service_T s, ssl_connection * ssl) {  static int remote_status(Service_T s) {
241    
242    ASSERT(s);    ASSERT(s);
243        
# Line 270  static int remote_status(Service_T s, ss Line 245  static int remote_status(Service_T s, ss
245            
246      /* If a monit daemon exist we request status information from the server */      /* If a monit daemon exist we request status information from the server */
247            
248      int sock= create_socket(Run.bind_addr?Run.bind_addr:"localhost",      Socket_T sock= socket_new(Run.bind_addr?Run.bind_addr:"localhost",
249                              Run.httpdport, SOCK_STREAM);                                Run.httpdport, SOCK_STREAM, Run.httpdssl);
250      if(sock<0) {      if(!sock) {
251    
252        fprintf(stdout,        fprintf(stdout,
253                "Cannot connect to monit server to get extended service data.\n");                "Cannot connect to monit server to get extended service data.\n");
254        local_status(s);        local_status(s);
255          
256        return FALSE;        return FALSE;
257                            
258      } else {      } else {
# Line 291  static int remote_status(Service_T s, ss Line 266  static int remote_status(Service_T s, ss
266                 "GET /%s?action=status HTTP/1.0\r\n%s\r\n", s->name, auth);                 "GET /%s?action=status HTTP/1.0\r\n%s\r\n", s->name, auth);
267                
268        free(auth);        free(auth);
   
       if(ssl != NULL) {  
   
         if(!embed_ssl_socket(ssl, sock)) {  
   
           fprintf(stdout, "Failed to establish SSL communication to monit"  
                   " server\n");  
           local_status(s);  
269                
270            return FALSE;        socket_write(sock, req, sizeof(req));
         }  
   
         send_ssl_socket(ssl, req, sizeof(req));  
         if(0>(n= recv_ssl_socket(ssl, buf, STRLEN))) {  
             
           local_status(s);  
           close_ssl_socket(ssl);  
           close_socket(sock);  
             
           return TRUE;  
           
         }  
   
         close_ssl_socket(ssl);  
         close_socket(sock);  
   
       } else {  
   
         sock_send(sock, req, sizeof(req), 0);  
271                
272          if(0>(n= sock_recv(sock, buf, STRLEN, 0))) {        if(0>(n= socket_read(sock, buf, STRLEN))) {
273                      
274            local_status(s);          local_status(s);
275            close_socket(sock);          socket_close(&sock);
             
           return TRUE;  
276                    
277          }          return TRUE;
278                    
         close_socket(sock);  
279        }        }
280                
281          socket_close(&sock);
282            
283    
284        /* If everything has gone well the returned string starts with        /* If everything has gone well the returned string starts with
285           "Process ", "Device ", "File " or "Directory " */           "Process ", "Device ", "File " or "Directory " */
286          
287        buf[n]= 0;        buf[n]= 0;
288        if(starts_with(buf, "Process ") ||        if(starts_with(buf, "Process ") ||
289           starts_with(buf, "Device ") ||           starts_with(buf, "Device ") ||
290           starts_with(buf, "File ") ||           starts_with(buf, "File ") ||
291           starts_with(buf, "Directory ")) {           starts_with(buf, "Directory ")) {
292            
293          fprintf(stdout, "%s", buf);          fprintf(stdout, "%s", buf);
294                    
295        } else {        } else {

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

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