45 |
|
|
46 |
/* Private Prototypes */ |
/* Private Prototypes */ |
47 |
static void local_status(Process_T); |
static void local_status(Process_T); |
48 |
static int remote_status(Process_T); |
static int remote_status(Process_T, ssl_connection *); |
49 |
|
|
50 |
/** |
/** |
51 |
* Print the status of processes in the process list. |
* Print the status of processes in the process list. |
68 |
Process_T p; |
Process_T p; |
69 |
char *uptime= get_process_uptime(Run.pidfile); |
char *uptime= get_process_uptime(Run.pidfile); |
70 |
int remote= TRUE; |
int remote= TRUE; |
71 |
|
ssl_connection * ssl= NULL; |
72 |
|
|
73 |
|
if ( Run.httpdssl ) { |
74 |
|
|
75 |
|
ssl = new_ssl_connection(); |
76 |
|
|
77 |
|
} |
78 |
|
|
79 |
fprintf(stdout, "monit daemon uptime: %s\n", uptime); |
fprintf(stdout, "monit daemon uptime: %s\n", uptime); |
80 |
free(uptime); |
free(uptime); |
81 |
|
|
83 |
|
|
84 |
if (remote) { |
if (remote) { |
85 |
|
|
86 |
remote = remote_status(p); |
remote = remote_status(p, ssl); |
87 |
|
|
88 |
} else { |
} else { |
89 |
|
|
92 |
} |
} |
93 |
|
|
94 |
} |
} |
95 |
|
|
96 |
|
if ( Run.httpdssl ) { |
97 |
|
|
98 |
|
delete_ssl_socket(ssl); |
99 |
|
|
100 |
|
} |
101 |
|
|
102 |
} |
} |
103 |
|
|
109 |
|
|
110 |
Process_T p; |
Process_T p; |
111 |
int remote= TRUE; |
int remote= TRUE; |
112 |
|
ssl_connection * ssl= NULL; |
113 |
|
|
114 |
|
if ( Run.httpdssl ) { |
115 |
|
|
116 |
|
ssl = new_ssl_connection(); |
117 |
|
|
118 |
|
} |
119 |
|
|
120 |
for ( p= processlist; p; p= p->next) { |
for ( p= processlist; p; p= p->next) { |
121 |
|
|
123 |
|
|
124 |
if (remote) { |
if (remote) { |
125 |
|
|
126 |
remote = remote_status(p); |
remote = remote_status(p, ssl); |
127 |
|
|
128 |
} else { |
} else { |
129 |
|
|
135 |
|
|
136 |
} |
} |
137 |
|
|
138 |
|
if ( Run.httpdssl ) { |
139 |
|
|
140 |
|
delete_ssl_socket(ssl); |
141 |
|
|
142 |
|
} |
143 |
} |
} |
144 |
|
|
145 |
/* ----------------------------------------------------------------- Private */ |
/* ----------------------------------------------------------------- Private */ |
183 |
* @param p A Process_T object |
* @param p A Process_T object |
184 |
* @return TRUE if the monit server could be connected |
* @return TRUE if the monit server could be connected |
185 |
*/ |
*/ |
186 |
static int remote_status(Process_T p) { |
static int remote_status(Process_T p, ssl_connection * ssl) { |
187 |
|
|
188 |
if ( exist_daemon() ) { |
if ( exist_daemon() ) { |
189 |
|
|
210 |
"GET /%s?action=status HTTP/1.0\r\n%s\r\n", p->name, auth); |
"GET /%s?action=status HTTP/1.0\r\n%s\r\n", p->name, auth); |
211 |
|
|
212 |
free(auth); |
free(auth); |
213 |
sock_send(s, req, sizeof(req), 0); |
|
214 |
|
if ( ssl != NULL ) { |
215 |
|
|
216 |
|
if (!embed_ssl_socket(ssl, s)) { |
217 |
|
|
218 |
|
fprintf(stdout, "Failed establish SSL communication to monit" |
219 |
|
" server\n"); |
220 |
|
local_status(p); |
221 |
|
|
222 |
|
return FALSE; |
223 |
|
} |
224 |
|
|
225 |
|
send_ssl_socket(ssl, req, sizeof(req)); |
226 |
|
|
227 |
if(0>(n= sock_recv(s, buf, STRLEN, 0))) { |
if(0>(n= recv_ssl_socket(ssl, buf, STRLEN))) { |
228 |
|
|
229 |
|
local_status(p); |
230 |
|
close_ssl_socket(ssl); |
231 |
|
close_socket(s); |
232 |
|
|
233 |
|
return TRUE; |
234 |
|
|
235 |
local_status(p); |
} |
236 |
|
|
237 |
|
close_ssl_socket(ssl); |
238 |
close_socket(s); |
close_socket(s); |
239 |
|
|
240 |
|
} else { |
241 |
|
|
242 |
|
sock_send(s, req, sizeof(req), 0); |
243 |
|
|
244 |
|
if(0>(n= sock_recv(s, buf, STRLEN, 0))) { |
245 |
|
|
246 |
|
local_status(p); |
247 |
|
close_socket(s); |
248 |
|
|
249 |
|
return TRUE; |
250 |
|
|
251 |
return TRUE; |
} |
252 |
|
|
253 |
|
close_socket(s); |
254 |
} |
} |
255 |
|
|
|
close_socket(s); |
|
256 |
|
|
257 |
/* If everything has gone well the returned string starts with |
/* If everything has gone well the returned string starts with |
258 |
"Process " */ |
"Process " */ |