"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/http/cervlet.c" between
monit-5.27.2.tar.gz and monit-5.28.0.tar.gz

About: Monit is a utility for managing and monitoring processes, files, directories and filesystems (with automatic error recovery).

cervlet.c  (monit-5.27.2):cervlet.c  (monit-5.28.0)
skipping to change at line 86 skipping to change at line 86
#include "monit.h" #include "monit.h"
#include "cervlet.h" #include "cervlet.h"
#include "engine.h" #include "engine.h"
#include "processor.h" #include "processor.h"
#include "base64.h" #include "base64.h"
#include "event.h" #include "event.h"
#include "alert.h" #include "alert.h"
#include "ProcessTree.h" #include "ProcessTree.h"
#include "device.h" #include "device.h"
#include "protocol.h" #include "protocol.h"
#include "Color.h" #include "TextColor.h"
#include "Box.h" #include "TextBox.h"
#define ACTION(c) ! strncasecmp(req->url, c, sizeof(c)) #define ACTION(c) ! strncasecmp(req->url, c, sizeof(c))
/* URL Commands supported */ /* URL Commands supported */
#define HOME "/" #define HOME "/"
#define TEST "/_monit" #define TEST "/_monit"
#define ABOUT "/_about" #define ABOUT "/_about"
#define PING "/_ping" #define PING "/_ping"
#define GETID "/_getid" #define GETID "/_getid"
#define STATUS "/_status" #define STATUS "/_status"
skipping to change at line 111 skipping to change at line 111
#define RUNTIME "/_runtime" #define RUNTIME "/_runtime"
#define VIEWLOG "/_viewlog" #define VIEWLOG "/_viewlog"
#define DOACTION "/_doaction" #define DOACTION "/_doaction"
#define FAVICON "/favicon.ico" #define FAVICON "/favicon.ico"
typedef enum { typedef enum {
TXT = 0, TXT = 0,
HTML HTML
} __attribute__((__packed__)) Output_Type; } __attribute__((__packed__)) Output_Type;
typedef struct ServiceMap_T {
int found;
union {
struct {
const char *name;
const char *token;
Action_Type id;
} action;
struct {
HttpResponse res;
} status;
struct {
TextBox_T box;
} summary;
} data;
} *ServiceMap_T;
/* Private prototypes */ /* Private prototypes */
static bool is_readonly(HttpRequest); static bool is_readonly(HttpRequest);
static void printFavicon(HttpResponse); static void printFavicon(HttpResponse);
static void doGet(HttpRequest, HttpResponse); static void doGet(HttpRequest, HttpResponse);
static void doPost(HttpRequest, HttpResponse); static void doPost(HttpRequest, HttpResponse);
static void do_head(HttpResponse res, const char *path, const char *name, int re fresh); static void do_head(HttpResponse res, const char *path, const char *name, int re fresh);
static void do_foot(HttpResponse res); static void do_foot(HttpResponse res);
static void do_home(HttpResponse); static void do_home(HttpResponse);
static void do_home_system(HttpResponse); static void do_home_system(HttpResponse);
static void do_home_filesystem(HttpResponse); static void do_home_filesystem(HttpResponse);
skipping to change at line 200 skipping to change at line 217
/** /**
* Callback hook to the Processor module for registering this modules * Callback hook to the Processor module for registering this modules
* doGet and doPost methods. * doGet and doPost methods.
*/ */
void init_service() { void init_service() {
add_Impl(doGet, doPost); add_Impl(doGet, doPost);
} }
/* ----------------------------------------------------------------- Private */ /* ----------------------------------------------------------------- Private */
static void _printServiceSummary(TextBox_T t, Service_T s) {
TextBox_setColumn(t, 1, "%s", s->name);
TextBox_setColumn(t, 2, "%s", get_service_status(TXT, s, (char[STRLEN]){
}, STRLEN));
TextBox_setColumn(t, 3, "%s", servicetypes[s->type]);
TextBox_printRow(t);
}
static void _serviceMapByName(const char *pattern, void (*callback)(Service_T s,
ServiceMap_T ap), ServiceMap_T ap) {
// Check the service name using the following sequence:
// 1) if the pattern is NULL, any service will match
// 2) backard compatibility: before monit 5.28.0 there was no support fo
r regular expresion => check verbatim match before trying regex (the service may
contain special characters)
// 3) regex match
if (pattern) {
int rv;
regex_t r;
char patternEscaped[STRLEN];
const char *patternCursor;
// If the pattern doesn't contain "^" or "$" already, wrap it as
"^<pattern>$" to prevent match with services that contain the given substring o
nly
if (! Str_has("^$", pattern)) {
snprintf(patternEscaped, sizeof(patternEscaped), "^%s$",
pattern);
patternCursor = patternEscaped;
} else {
patternCursor = pattern;
}
// The pattern is set, try to compile it as regex
if ((rv = regcomp(&r, patternCursor, REG_NOSUB | REG_EXTENDED)))
{
// Pattern compilation failed, fallback to verbatim matc
h (before monit 5.28.0 there was no support for regular expresion)
char error[STRLEN];
regerror(rv, &r, error, STRLEN);
regfree(&r);
DEBUG("Regex %s parsing error: %s\n", patternCursor, err
or);
for (Service_T s = servicelist_conf; s; s = s->next_conf
) {
if (IS(pattern, s->name)) { // Use the unescaped
/original pattern
callback(s, ap);
ap->found++;
}
}
} else {
// Regular expression match
for (Service_T s = servicelist_conf; s; s = s->next_conf
) {
if (! regexec(&r, s->name, 0, NULL, 0)) {
callback(s, ap);
ap->found++;
}
}
regfree(&r);
}
} else {
// Pattern is not set, any service will match
for (Service_T s = servicelist_conf; s; s = s->next_conf) {
callback(s, ap);
ap->found++;
}
}
}
static void _serviceMapByType(Service_Type type, void (*callback)(Service_T s, S
erviceMap_T ap), ServiceMap_T ap) {
for (Service_T s = servicelist_conf; s; s = s->next_conf) {
if (s->type == type) {
callback(s, ap);
ap->found++;
}
}
}
static void _serviceMapSummary(Service_T s, ServiceMap_T ap) {
_printServiceSummary(ap->data.summary.box, s);
}
static void _serviceMapStatus(Service_T s, ServiceMap_T ap) {
status_service_txt(s, ap->data.status.res);
}
static void _serviceMapAction(Service_T s, ServiceMap_T ap) {
s->doaction = ap->data.action.id;
Log_info("'%s' %s on user request\n", s->name, ap->data.action.name);
}
static char *_getUptime(time_t delta, char s[256]) { static char *_getUptime(time_t delta, char s[256]) {
static int min = 60; static int min = 60;
static int hour = 3600; static int hour = 3600;
static int day = 86400; static int day = 86400;
long rest_d; long rest_d;
long rest_h; long rest_h;
long rest_m; long rest_m;
char *p = s; char *p = s;
if (delta < 0) { if (delta < 0) {
skipping to change at line 239 skipping to change at line 339
} else { } else {
StringBuffer_append(res->outputbuffer, " %-28s ", name); StringBuffer_append(res->outputbuffer, " %-28s ", name);
} }
if (! validValue) { if (! validValue) {
StringBuffer_append(res->outputbuffer, type == HTML ? "<td class ='gray-text'>-</td>" : COLOR_DARKGRAY "-" COLOR_RESET); StringBuffer_append(res->outputbuffer, type == HTML ? "<td class ='gray-text'>-</td>" : COLOR_DARKGRAY "-" COLOR_RESET);
} else { } else {
va_list ap; va_list ap;
va_start(ap, value); va_start(ap, value);
char *_value = Str_vcat(value, ap); char *_value = Str_vcat(value, ap);
va_end(ap); va_end(ap);
if (errorType != Event_Null && s->error & errorType) if (errorType != Event_Null && s->error & errorType)
StringBuffer_append(res->outputbuffer, type == HTML ? "< td class='red-text'>" : COLOR_LIGHTRED); StringBuffer_append(res->outputbuffer, type == HTML ? "< td class='red-text'>" : COLOR_LIGHTRED);
else else
StringBuffer_append(res->outputbuffer, type == HTML ? "< td>" : COLOR_DEFAULT); StringBuffer_append(res->outputbuffer, type == HTML ? "< td>" : COLOR_DEFAULT);
if (type == HTML) { if (type == HTML) {
// If the output contains multiple line, wrap use <pre>, otherwise keep as is // If the output contains multiple line, wrap use <pre>, otherwise keep as is
bool multiline = strrchr(_value, '\n') ? true : false; bool multiline = strrchr(_value, '\n') ? true : false;
if (multiline) if (multiline)
StringBuffer_append(res->outputbuffer, "<pre>"); StringBuffer_append(res->outputbuffer, "<pre>");
escapeHTML(res->outputbuffer, _value); escapeHTML(res->outputbuffer, _value);
StringBuffer_append(res->outputbuffer, "%s</td>", multil ine ? "</pre>" : ""); StringBuffer_append(res->outputbuffer, "%s</td>", multil ine ? "</pre>" : "");
} else { } else {
int column = 0; int column = 0;
for (int i = 0; _value[i]; i++) { for (int i = 0; _value[i]; i++) {
skipping to change at line 469 skipping to change at line 571
_formatStatus("last exit value", Event_S tatus, type, res, s, true, "%d", s->program->exitStatus); _formatStatus("last exit value", Event_S tatus, type, res, s, true, "%d", s->program->exitStatus);
_formatStatus("last output", Event_Statu s, type, res, s, StringBuffer_length(s->program->lastOutput), "%s", StringBuffer _toString(s->program->lastOutput)); _formatStatus("last output", Event_Statu s, type, res, s, StringBuffer_length(s->program->lastOutput), "%s", StringBuffer _toString(s->program->lastOutput));
} }
break; break;
default: default:
break; break;
} }
for (Icmp_T i = s->icmplist; i; i = i->next) { for (Icmp_T i = s->icmplist; i; i = i->next) {
if (i->is_available == Connection_Failed) if (i->is_available == Connection_Failed)
_formatStatus("ping response time", Event_Icmp, type, res, s, true, "connection failed"); _formatStatus("ping response time", i->check_inv ers ? Event_Null : Event_Icmp, type, res, s, true, "connection failed");
else else
_formatStatus("ping response time", Event_Null, type, res, s, i->is_available != Connection_Init && i->response >= 0., "%s", Con vert_time2str(i->response, (char[11]){})); _formatStatus("ping response time", i->check_inv ers ? Event_Icmp : Event_Null, type, res, s, i->is_available != Connection_Init && i->responsetime.current >= 0., "%s", Convert_time2str(i->responsetime.current , (char[11]){}));
} }
for (Port_T p = s->portlist; p; p = p->next) { for (Port_T p = s->portlist; p; p = p->next) {
if (p->is_available == Connection_Failed) { if (p->is_available == Connection_Failed) {
_formatStatus("port response time", Event_Connec Event_Type highlight = p->check_invers ? Event_N
tion, type, res, s, true, "FAILED to [%s]:%d%s type %s/%s %sprotocol %s", p->hos ull : Event_Connection;
tname, p->target.net.port, Util_portRequestDescription(p), Util_portTypeDescript _formatStatus("port response time", highlight, t
ion(p), Util_portIpDescription(p), p->target.net.ssl.options.flags ? "using TLS ype, res, s, true, "FAILED to [%s]:%d%s type %s/%s %sprotocol %s", p->hostname,
" : "", p->protocol->name); p->target.net.port, Util_portRequestDescription(p), Util_portTypeDescription(p),
Util_portIpDescription(p), p->target.net.ssl.options.flags ? "using TLS " : "",
p->protocol->name);
} else { } else {
char buf[STRLEN] = {}; char buf[STRLEN] = {};
if (p->target.net.ssl.options.flags) if (p->target.net.ssl.options.flags)
snprintf(buf, sizeof(buf), "using TLS (c ertificate valid for %d days) ", p->target.net.ssl.certificate.validDays); snprintf(buf, sizeof(buf), "using TLS (c ertificate valid for %d days) ", p->target.net.ssl.certificate.validDays);
_formatStatus("port response time", p->target.ne Event_Type highlight = p->check_invers ? Event_C
t.ssl.certificate.validDays < p->target.net.ssl.certificate.minimumDays ? Event_ onnection : Event_Null;
Timestamp : Event_Null, type, res, s, p->is_available != Connection_Init, "%s to if (p->target.net.ssl.certificate.validDays < p-
%s:%d%s type %s/%s %sprotocol %s", Convert_time2str(p->response, (char[11]){}), >target.net.ssl.certificate.minimumDays)
p->hostname, p->target.net.port, Util_portRequestDescription(p), Util_portTypeD highlight |= Event_Timestamp;
escription(p), Util_portIpDescription(p), buf, p->protocol->name); _formatStatus("port response time", highlight, t
ype, res, s, p->is_available != Connection_Init, "%s to %s:%d%s type %s/%s %spro
tocol %s", Convert_time2str(p->responsetime.current, (char[11]){}), p->hostname,
p->target.net.port, Util_portRequestDescription(p), Util_portTypeDescription(p)
, Util_portIpDescription(p), buf, p->protocol->name);
} }
} }
for (Port_T p = s->socketlist; p; p = p->next) { for (Port_T p = s->socketlist; p; p = p->next) {
if (p->is_available == Connection_Failed) { if (p->is_available == Connection_Failed) {
_formatStatus("unix socket response time", Event _Connection, type, res, s, true, "FAILED to %s type %s protocol %s", p->target.u nix.pathname, Util_portTypeDescription(p), p->protocol->name); _formatStatus("unix socket response time", p->ch eck_invers ? Event_Null : Event_Connection, type, res, s, true, "FAILED to %s ty pe %s protocol %s", p->target.unix.pathname, Util_portTypeDescription(p), p->pro tocol->name);
} else { } else {
_formatStatus("unix socket response time", Event _Null, type, res, s, p->is_available != Connection_Init, "%s to %s type %s proto col %s", Convert_time2str(p->response, (char[11]){}), p->target.unix.pathname, U til_portTypeDescription(p), p->protocol->name); _formatStatus("unix socket response time", p->ch eck_invers ? Event_Connection : Event_Null, type, res, s, p->is_available != Con nection_Init, "%s to %s type %s protocol %s", Convert_time2str(p->responsetime.c urrent, (char[11]){}), p->target.unix.pathname, Util_portTypeDescription(p), p-> protocol->name);
} }
} }
} }
_formatStatus("data collected", Event_Null, type, res, s, true, "%s", Ti me_string(s->collected.tv_sec, (char[32]){})); _formatStatus("data collected", Event_Null, type, res, s, true, "%s", Ti me_string(s->collected.tv_sec, (char[32]){}));
} }
__attribute__((format (printf, 5, 6))) static void _displayTableRow(HttpResponse res, bool escape, const char *class, const char *key, const char *value, ...) { __attribute__((format (printf, 5, 6))) static void _displayTableRow(HttpResponse res, bool escape, const char *class, const char *key, const char *value, ...) {
va_list ap; va_list ap;
va_start(ap, value); va_start(ap, value);
char *_value = Str_vcat(value, ap); char *_value = Str_vcat(value, ap);
skipping to change at line 692 skipping to change at line 798
"</table>"\ "</table>"\
"<center>", "<center>",
StringBuffer_toString(system_htmlescaped), refresh, path, name, VERSION); StringBuffer_toString(system_htmlescaped), refresh, path, name, VERSION);
StringBuffer_free(&system_htmlescaped); StringBuffer_free(&system_htmlescaped);
} }
static void do_foot(HttpResponse res) { static void do_foot(HttpResponse res) {
StringBuffer_append(res->outputbuffer, StringBuffer_append(res->outputbuffer,
"</center></div></div>" "</center></div></div>"
"<div id='footer'>" "<div id='footer'>"
"Copyright &copy; 2001-2020 <a href=\"http://tildesl ash.com/\">Tildeslash</a>. All rights reserved. " "Copyright &copy; 2001-2021 <a href=\"http://tildesl ash.com/\">Tildeslash</a>. All rights reserved. "
"<span style='margin-left:5px;'></span>" "<span style='margin-left:5px;'></span>"
"<a href=\"http://mmonit.com/monit/\">Monit web site </a> | " "<a href=\"http://mmonit.com/monit/\">Monit web site </a> | "
"<a href=\"http://mmonit.com/wiki/\">Monit Wiki</a> | " "<a href=\"http://mmonit.com/wiki/\">Monit Wiki</a> | "
"<a href=\"http://mmonit.com/\">M/Monit</a>" "<a href=\"http://mmonit.com/\">M/Monit</a>"
"</div></body></html>"); "</div></body></html>");
} }
static void do_home(HttpResponse res) { static void do_home(HttpResponse res) {
do_head(res, "", "", Run.polltime); do_head(res, "", "", Run.polltime);
StringBuffer_T system_htmlescaped = escapeHTML(StringBuffer_create(16), Run.system->name); StringBuffer_T system_htmlescaped = escapeHTML(StringBuffer_create(16), Run.system->name);
skipping to change at line 735 skipping to change at line 841
do_foot(res); do_foot(res);
} }
static void do_about(HttpResponse res) { static void do_about(HttpResponse res) {
StringBuffer_append(res->outputbuffer, StringBuffer_append(res->outputbuffer,
"<html><head><title>about monit</title></head><body bgcolor=white>" "<html><head><title>about monit</title></head><body bgcolor=white>"
"<br><h1><center><a href='http://mmonit.com/monit/'> " "<br><h1><center><a href='http://mmonit.com/monit/'> "
"monit " VERSION "</a></center></h1>"); "monit " VERSION "</a></center></h1>");
StringBuffer_append(res->outputbuffer, StringBuffer_append(res->outputbuffer,
"<ul>" "<ul>"
"<li style='padding-bottom:10px;'>Copyright &copy; 2 001-2020 <a " "<li style='padding-bottom:10px;'>Copyright &copy; 2 001-2021 <a "
"href='http://tildeslash.com/'>Tildeslash Ltd" "href='http://tildeslash.com/'>Tildeslash Ltd"
"</a>. All Rights Reserved.</li></ul>"); "</a>. All Rights Reserved.</li></ul>");
StringBuffer_append(res->outputbuffer, "<hr size='1'>"); StringBuffer_append(res->outputbuffer, "<hr size='1'>");
StringBuffer_append(res->outputbuffer, StringBuffer_append(res->outputbuffer,
"<p>This program is free software; you can redistrib ute it and/or " "<p>This program is free software; you can redistrib ute it and/or "
"modify it under the terms of the GNU Affero General Public License version 3</p>" "modify it under the terms of the GNU Affero General Public License version 3</p>"
"<p>This program is distributed in the hope that it will be useful, but " "<p>This program is distributed in the hope that it will be useful, but "
"WITHOUT ANY WARRANTY; without even the implied warr anty of " "WITHOUT ANY WARRANTY; without even the implied warr anty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the " "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the "
"<a href='http://www.gnu.org/licenses/agpl.html'>" "<a href='http://www.gnu.org/licenses/agpl.html'>"
skipping to change at line 965 skipping to change at line 1071
return; return;
} }
Service_T s = Util_getService(++name); Service_T s = Util_getService(++name);
if (! s) { if (! s) {
send_error(req, res, SC_NOT_FOUND, "There is no service named \" %s\"", name); send_error(req, res, SC_NOT_FOUND, "There is no service named \" %s\"", name);
return; return;
} }
do_service(req, res, s); do_service(req, res, s);
} }
// Do action for the service (the service name is the last component of the URL path)
static void handle_service_action(HttpRequest req, HttpResponse res) { static void handle_service_action(HttpRequest req, HttpResponse res) {
char *name = req->url; char *name = req->url;
if (! name) { if (! name) {
send_error(req, res, SC_NOT_FOUND, "Service name required"); send_error(req, res, SC_NOT_FOUND, "Service name required");
return; return;
} }
Service_T s = Util_getService(++name); struct ServiceMap_T ap = {.found = 0, .data.action.name = get_parameter(
if (! s) { req, "action")};
send_error(req, res, SC_NOT_FOUND, "There is no service named \" if (ap.data.action.name) {
%s\"", name);
return;
}
const char *action = get_parameter(req, "action");
if (action) {
if (is_readonly(req)) { if (is_readonly(req)) {
send_error(req, res, SC_FORBIDDEN, "You do not have suff icient privileges to access this page"); send_error(req, res, SC_FORBIDDEN, "You do not have suff icient privileges to access this page");
return; } else {
} ap.data.action.id = Util_getAction(ap.data.action.name);
Action_Type doaction = Util_getAction(action); if (ap.data.action.id == Action_Ignored) {
if (doaction == Action_Ignored) { send_error(req, res, SC_BAD_REQUEST, "Invalid ac
send_error(req, res, SC_BAD_REQUEST, "Invalid action \"% tion \"%s\"", ap.data.action.name);
s\"", action); } else {
return; Service_T s = Util_getService(++name);
if (! s) {
send_error(req, res, SC_NOT_FOUND, "Ther
e is no service named \"%s\"", name);
return;
}
_serviceMapAction(s, &ap);
Run.flags |= Run_ActionPending; /* set the globa
l flag */
do_wakeupcall();
do_service(req, res, s);
}
} }
s->doaction = doaction;
const char *token = get_parameter(req, "token");
if (token) {
FREE(s->token);
s->token = Str_dup(token);
}
Log_info("'%s' %s on user request\n", s->name, action);
Run.flags |= Run_ActionPending; /* set the global flag */
do_wakeupcall();
} }
do_service(req, res, s);
} }
// Do action for all services listed in "service" HTTP parameter (may have multi ple value)
static void handle_doaction(HttpRequest req, HttpResponse res) { static void handle_doaction(HttpRequest req, HttpResponse res) {
Service_T s; struct ServiceMap_T ap = {.found = 0, .data.action.name = get_parameter(
Action_Type doaction = Action_Ignored; req, "action")};
const char *action = get_parameter(req, "action"); if (ap.data.action.name) {
const char *token = get_parameter(req, "token");
if (action) {
if (is_readonly(req)) { if (is_readonly(req)) {
send_error(req, res, SC_FORBIDDEN, "You do not have suff icient privileges to access this page"); send_error(req, res, SC_FORBIDDEN, "You do not have suff icient privileges to access this page");
return; return;
} } else {
if ((doaction = Util_getAction(action)) == Action_Ignored) { if ((ap.data.action.id = Util_getAction(ap.data.action.n
send_error(req, res, SC_BAD_REQUEST, "Invalid action \"% ame)) == Action_Ignored) {
s\"", action); send_error(req, res, SC_BAD_REQUEST, "Invalid ac
return; tion \"%s\"", ap.data.action.name);
} return;
for (HttpParameter p = req->params; p; p = p->next) { }
if (IS(p->name, "service")) { for (HttpParameter p = req->params; p; p = p->next) {
s = Util_getService(p->value); if (IS(p->name, "service")) {
if (! s) { _serviceMapByName(p->value, _serviceMapA
send_error(req, res, SC_BAD_REQUEST, "Th ction, &ap);
ere is no service named \"%s\"", p->value ? p->value : ""); if (ap.found == 0) {
return; send_error(req, res, SC_BAD_REQU
EST, "There is no service named \"%s\"", p->value ? p->value : "");
return;
}
} }
s->doaction = doaction;
Log_info("'%s' %s on user request\n", s->name, a
ction);
} }
} if (ap.found > 0) {
/* Set token for last service only so we'll get it back after al Run.flags |= Run_ActionPending;
l services were handled */ do_wakeupcall();
if (token) {
Service_T q = NULL;
for (s = servicelist; s; s = s->next)
if (s->doaction == doaction)
q = s;
if (q) {
FREE(q->token);
q->token = Str_dup(token);
} }
} }
Run.flags |= Run_ActionPending;
do_wakeupcall();
} }
} }
static void handle_runtime(HttpRequest req, HttpResponse res) { static void handle_runtime(HttpRequest req, HttpResponse res) {
LOCK(Run.mutex) LOCK(Run.mutex)
do_runtime(req, res); do_runtime(req, res);
END_LOCK; END_LOCK;
} }
static void handle_runtime_action(HttpRequest req, HttpResponse res) { static void handle_runtime_action(HttpRequest req, HttpResponse res) {
skipping to change at line 1800 skipping to change at line 1889
for (ActionRate_T ar = s->actionratelist; ar; ar = ar->next) { for (ActionRate_T ar = s->actionratelist; ar; ar = ar->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Timeout", "If restarted %d times within %d cycle(s) then %s", ar->count, ar->cycle, StringBuffer_toString(U til_printAction(ar->action->failed, sb))); _displayTableRow(res, true, "rule", "Timeout", "If restarted %d times within %d cycle(s) then %s", ar->count, ar->cycle, StringBuffer_toString(U til_printAction(ar->action->failed, sb)));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_nonexistence(HttpResponse res, Service_T s) { static void print_service_rules_nonexistence(HttpResponse res, Service_T s) {
for (NonExist_T l = s->nonexistlist; l; l = l->next) { for (NonExist_T l = s->nonexistlist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Existence", "%s", StringBuf fer_toString(Util_printRule(sb, l->action, "If doesn't exist"))); _displayTableRow(res, true, "rule", "Existence", "%s", StringBuf fer_toString(Util_printRule(false, sb, l->action, "If doesn't exist")));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_existence(HttpResponse res, Service_T s) { static void print_service_rules_existence(HttpResponse res, Service_T s) {
for (Exist_T l = s->existlist; l; l = l->next) { for (Exist_T l = s->existlist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Non-Existence", "%s", Strin gBuffer_toString(Util_printRule(sb, l->action, "If exist"))); _displayTableRow(res, true, "rule", "Non-Existence", "%s", Strin gBuffer_toString(Util_printRule(false, sb, l->action, "If exist")));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_port(HttpResponse res, Service_T s) { static void print_service_rules_port(HttpResponse res, Service_T s) {
for (Port_T p = s->portlist; p; p = p->next) { for (Port_T p = s->portlist; p; p = p->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
StringBuffer_T buf = StringBuffer_create(64); StringBuffer_T buf = StringBuffer_create(64);
StringBuffer_append(buf, "If failed [%s]:%d%s", StringBuffer_append(buf, "If %s [%s]:%d%s",
p->hostname, p->target.net.port, Util_portRequestDescrip p->check_invers ? "succeeded" : "failed", p->hostname, p
tion(p)); ->target.net.port, Util_portRequestDescription(p));
if (p->outgoing.ip) if (p->outgoing.ip)
StringBuffer_append(buf, " via address %s", p->outgoing. ip); StringBuffer_append(buf, " via address %s", p->outgoing. ip);
StringBuffer_append(buf, " type %s/%s protocol %s with timeout % s", StringBuffer_append(buf, " type %s/%s protocol %s with timeout % s",
Util_portTypeDescription(p), Util_portIpDescription(p), p->protocol->name, Convert_time2str(p->timeout, (char[11]){})); Util_portTypeDescription(p), Util_portIpDescription(p), p->protocol->name, Convert_time2str(p->timeout, (char[11]){}));
if (p->retry > 1) if (p->retry > 1)
StringBuffer_append(buf, " and retry %d times", p->retry ); StringBuffer_append(buf, " and retry %d times", p->retry );
if (p->responsetime.limit > -1.)
StringBuffer_append(buf, " and responsetime %s %s", oper
atornames[p->responsetime.operator], Convert_time2str(p->responsetime.limit, (ch
ar[11]){}));
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
if (p->target.net.ssl.options.flags) { if (p->target.net.ssl.options.flags) {
StringBuffer_append(buf, " using TLS"); StringBuffer_append(buf, " using TLS");
const char *options = Ssl_printOptions(&p->target.net.ss l.options, (char[STRLEN]){}, STRLEN); const char *options = Ssl_printOptions(&p->target.net.ss l.options, (char[STRLEN]){}, STRLEN);
if (options && *options) if (options && *options)
StringBuffer_append(buf, " with options {%s}", o ptions); StringBuffer_append(buf, " with options {%s}", o ptions);
if (p->target.net.ssl.certificate.minimumDays > 0) if (p->target.net.ssl.certificate.minimumDays > 0)
StringBuffer_append(buf, " and certificate valid for at least %d days", p->target.net.ssl.certificate.minimumDays); StringBuffer_append(buf, " and certificate valid for at least %d days", p->target.net.ssl.certificate.minimumDays);
if (p->target.net.ssl.options.checksum) if (p->target.net.ssl.options.checksum)
StringBuffer_append(buf, " and certificate check sum %s equal to '%s'", checksumnames[p->target.net.ssl.options.checksumType], p- >target.net.ssl.options.checksum); StringBuffer_append(buf, " and certificate check sum %s equal to '%s'", checksumnames[p->target.net.ssl.options.checksumType], p- >target.net.ssl.options.checksum);
} }
#endif #endif
_displayTableRow(res, true, "rule", "Port", "%s", StringBuffer_t oString(Util_printRule(sb, p->action, "%s", StringBuffer_toString(buf)))); _displayTableRow(res, true, "rule", "Port", "%s", StringBuffer_t oString(Util_printRule(p->check_invers, sb, p->action, "%s", StringBuffer_toStri ng(buf))));
StringBuffer_free(&buf); StringBuffer_free(&buf);
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_socket(HttpResponse res, Service_T s) { static void print_service_rules_socket(HttpResponse res, Service_T s) {
for (Port_T p = s->socketlist; p; p = p->next) { for (Port_T p = s->socketlist; p; p = p->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
StringBuffer_T buf = StringBuffer_create(64);
StringBuffer_append(buf, "If %s %s type %s protocol %s with time
out %s", p->check_invers ? "succeeded" : "failed", p->target.unix.pathname, Util
_portTypeDescription(p), p->protocol->name, Convert_time2str(p->timeout, (char[1
1]){}));
if (p->retry > 1) if (p->retry > 1)
Util_printRule(sb, p->action, "If failed %s type %s prot StringBuffer_append(buf, " and retry %d times", p->retry
ocol %s with timeout %s and retry %d time(s)", p->target.unix.pathname, Util_por );
tTypeDescription(p), p->protocol->name, Convert_time2str(p->timeout, (char[11]){ if (p->responsetime.limit > -1.)
}), p->retry); StringBuffer_append(buf, " and responsetime %s %s", oper
else atornames[p->responsetime.operator], Convert_time2str(p->responsetime.limit, (ch
Util_printRule(sb, p->action, "If failed %s type %s prot ar[11]){}));
ocol %s with timeout %s", p->target.unix.pathname, Util_portTypeDescription(p), _displayTableRow(res, true, "rule", "Unix Socket", "%s", StringB
p->protocol->name, Convert_time2str(p->timeout, (char[11]){})); uffer_toString(Util_printRule(p->check_invers, sb, p->action, "%s", StringBuffer
_displayTableRow(res, true, "rule", "Unix Socket", "%s", StringB _toString(buf))));
uffer_toString(sb)); StringBuffer_free(&buf);
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_icmp(HttpResponse res, Service_T s) { static void print_service_rules_icmp(HttpResponse res, Service_T s) {
for (Icmp_T i = s->icmplist; i; i = i->next) { for (Icmp_T i = s->icmplist; i; i = i->next) {
const char *key; const char *key;
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
StringBuffer_T buf = StringBuffer_create(64);
switch (i->family) { switch (i->family) {
case Socket_Ip4: case Socket_Ip4:
key = "Ping4"; key = "Ping4";
break; break;
case Socket_Ip6: case Socket_Ip6:
key = "Ping6"; key = "Ping6";
break; break;
default: default:
key = "Ping"; key = "Ping";
break; break;
} }
_displayTableRow(res, true, "rule", key, "%s", StringBuffer_toSt StringBuffer_append(buf, "If %s count %d size %d with timeout %s
ring(Util_printRule(sb, i->action, "If failed [count %d size %d with timeout %s% ", i->check_invers ? "succeeded" : "failed", i->count, i->size, Convert_time2str
s%s]", i->count, i->size, Convert_time2str(i->timeout, (char[11]){}), i->outgoin (i->timeout, (char[11]){}));
g.ip ? " via address " : "", i->outgoing.ip ? i->outgoing.ip : ""))); if (i->outgoing.ip)
StringBuffer_append(buf, " via address %s", i->outgoing.
ip);
if (i->responsetime.limit > -1.)
StringBuffer_append(buf, " and responsetime %s %s", oper
atornames[i->responsetime.operator], Convert_time2str(i->responsetime.limit, (ch
ar[11]){}));
_displayTableRow(res, true, "rule", key, "%s", StringBuffer_toSt
ring(Util_printRule(i->check_invers, sb, i->action, "%s", StringBuffer_toString(
buf))));
StringBuffer_free(&buf);
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_perm(HttpResponse res, Service_T s) { static void print_service_rules_perm(HttpResponse res, Service_T s) {
if (s->perm) { if (s->perm) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (s->perm->test_changes) if (s->perm->test_changes)
Util_printRule(sb, s->perm->action, "If changed"); Util_printRule(false, sb, s->perm->action, "If changed") ;
else else
Util_printRule(sb, s->perm->action, "If failed %o", s->p erm->perm); Util_printRule(false, sb, s->perm->action, "If failed %o ", s->perm->perm);
_displayTableRow(res, true, "rule", "Permissions", "%s", StringB uffer_toString(sb)); _displayTableRow(res, true, "rule", "Permissions", "%s", StringB uffer_toString(sb));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_uid(HttpResponse res, Service_T s) { static void print_service_rules_uid(HttpResponse res, Service_T s) {
if (s->uid) { if (s->uid) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "UID", "%s", StringBuffer_to String(Util_printRule(sb, s->uid->action, "If failed %d", s->uid->uid))); _displayTableRow(res, true, "rule", "UID", "%s", StringBuffer_to String(Util_printRule(false, sb, s->uid->action, "If failed %d", s->uid->uid)));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_euid(HttpResponse res, Service_T s) { static void print_service_rules_euid(HttpResponse res, Service_T s) {
if (s->euid) { if (s->euid) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "EUID", "%s", StringBuffer_t oString(Util_printRule(sb, s->euid->action, "If failed %d", s->euid->uid))); _displayTableRow(res, true, "rule", "EUID", "%s", StringBuffer_t oString(Util_printRule(false, sb, s->euid->action, "If failed %d", s->euid->uid) ));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_filedescriptors(HttpResponse res, Service_T s) { static void print_service_rules_filedescriptors(HttpResponse res, Service_T s) {
for (Filedescriptors_T o = s->filedescriptorslist; o; o = o->next) { for (Filedescriptors_T o = s->filedescriptorslist; o; o = o->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (o->total) { if (o->total) {
_displayTableRow(res, true, "rule", "Total filedescripto rs", "%s", StringBuffer_toString(Util_printRule(sb, o->action, "If %s %lld", ope ratornames[o->operator], o->limit_absolute))); _displayTableRow(res, true, "rule", "Total filedescripto rs", "%s", StringBuffer_toString(Util_printRule(false, sb, o->action, "If %s %ll d", operatornames[o->operator], o->limit_absolute)));
} else { } else {
if (o->limit_absolute > -1LL) if (o->limit_absolute > -1LL)
_displayTableRow(res, true, "rule", "Filedescrip tors", "%s", StringBuffer_toString(Util_printRule(sb, o->action, "If %s %lld", o peratornames[o->operator], o->limit_absolute))); _displayTableRow(res, true, "rule", "Filedescrip tors", "%s", StringBuffer_toString(Util_printRule(false, sb, o->action, "If %s % lld", operatornames[o->operator], o->limit_absolute)));
else else
_displayTableRow(res, true, "rule", "Filedescrip tors", "%s", StringBuffer_toString(Util_printRule(sb, o->action, "If %s %.1f%%", operatornames[o->operator], o->limit_percent))); _displayTableRow(res, true, "rule", "Filedescrip tors", "%s", StringBuffer_toString(Util_printRule(false, sb, o->action, "If %s % .1f%%", operatornames[o->operator], o->limit_percent)));
} }
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_gid(HttpResponse res, Service_T s) { static void print_service_rules_gid(HttpResponse res, Service_T s) {
if (s->gid) { if (s->gid) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "GID", "%s", StringBuffer_to String(Util_printRule(sb, s->gid->action, "If failed %d", s->gid->gid))); _displayTableRow(res, true, "rule", "GID", "%s", StringBuffer_to String(Util_printRule(false, sb, s->gid->action, "If failed %d", s->gid->gid)));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_secattr(HttpResponse res, Service_T s) { static void print_service_rules_secattr(HttpResponse res, Service_T s) {
for (SecurityAttribute_T a = s->secattrlist; a; a = a->next) { for (SecurityAttribute_T a = s->secattrlist; a; a = a->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Security attribute", "%s", StringBuffer_toString(Util_printRule(sb, a->action, "If failed %s", a->attribute ))); _displayTableRow(res, true, "rule", "Security attribute", "%s", StringBuffer_toString(Util_printRule(false, sb, a->action, "If failed %s", a->at tribute)));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_timestamp(HttpResponse res, Service_T s) { static void print_service_rules_timestamp(HttpResponse res, Service_T s) {
for (Timestamp_T t = s->timestamplist; t; t = t->next) { for (Timestamp_T t = s->timestamplist; t; t = t->next) {
char key[STRLEN]; char key[STRLEN];
snprintf(key, sizeof(key), "%c%s", toupper(timestampnames[t->typ e][0]), timestampnames[t->type] + 1); snprintf(key, sizeof(key), "%c%s", toupper(timestampnames[t->typ e][0]), timestampnames[t->type] + 1);
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (t->test_changes) if (t->test_changes)
Util_printRule(sb, t->action, "If changed"); Util_printRule(false, sb, t->action, "If changed");
else else
Util_printRule(sb, t->action, "If %s %s", operatornames[ t->operator], Convert_time2str(t->time * 1000., (char[11]){})); Util_printRule(false, sb, t->action, "If %s %s", operato rnames[t->operator], Convert_time2str(t->time * 1000., (char[11]){}));
_displayTableRow(res, true, "rule", key, "%s", StringBuffer_toSt ring(sb)); _displayTableRow(res, true, "rule", key, "%s", StringBuffer_toSt ring(sb));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_fsflags(HttpResponse res, Service_T s) { static void print_service_rules_fsflags(HttpResponse res, Service_T s) {
for (FsFlag_T l = s->fsflaglist; l; l = l->next) { for (FsFlag_T l = s->fsflaglist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Filesystem flags", "%s", St ringBuffer_toString(Util_printRule(sb, l->action, "If changed"))); _displayTableRow(res, true, "rule", "Filesystem flags", "%s", St ringBuffer_toString(Util_printRule(false, sb, l->action, "If changed")));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_filesystem(HttpResponse res, Service_T s) { static void print_service_rules_filesystem(HttpResponse res, Service_T s) {
for (FileSystem_T dl = s->filesystemlist; dl; dl = dl->next) { for (FileSystem_T dl = s->filesystemlist; dl; dl = dl->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
switch (dl->resource) { switch (dl->resource) {
case Resource_Inode: case Resource_Inode:
if (dl->limit_absolute > -1) if (dl->limit_absolute > -1)
Util_printRule(sb, dl->action, "If %s %lld", ope ratornames[dl->operator], dl->limit_absolute); Util_printRule(false, sb, dl->action, "If %s %ll d", operatornames[dl->operator], dl->limit_absolute);
else else
Util_printRule(sb, dl->action, "If %s %.1f%%", o peratornames[dl->operator], dl->limit_percent); Util_printRule(false, sb, dl->action, "If %s %.1 f%%", operatornames[dl->operator], dl->limit_percent);
_displayTableRow(res, true, "rule", "Inodes usage limit" , "%s", StringBuffer_toString(sb)); _displayTableRow(res, true, "rule", "Inodes usage limit" , "%s", StringBuffer_toString(sb));
break; break;
case Resource_InodeFree: case Resource_InodeFree:
if (dl->limit_absolute > -1) if (dl->limit_absolute > -1)
Util_printRule(sb, dl->action, "If %s %lld", ope ratornames[dl->operator], dl->limit_absolute); Util_printRule(false, sb, dl->action, "If %s %ll d", operatornames[dl->operator], dl->limit_absolute);
else else
Util_printRule(sb, dl->action, "If %s %.1f%%", o peratornames[dl->operator], dl->limit_percent); Util_printRule(false, sb, dl->action, "If %s %.1 f%%", operatornames[dl->operator], dl->limit_percent);
_displayTableRow(res, true, "rule", "Inodes free limit", "%s", StringBuffer_toString(sb)); _displayTableRow(res, true, "rule", "Inodes free limit", "%s", StringBuffer_toString(sb));
break; break;
case Resource_Space: case Resource_Space:
if (dl->limit_absolute > -1) if (dl->limit_absolute > -1)
Util_printRule(sb, dl->action, "If %s %s", opera tornames[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){})); Util_printRule(false, sb, dl->action, "If %s %s" , operatornames[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){ }));
else else
Util_printRule(sb, dl->action, "If %s %.1f%%", o peratornames[dl->operator], dl->limit_percent); Util_printRule(false, sb, dl->action, "If %s %.1 f%%", operatornames[dl->operator], dl->limit_percent);
_displayTableRow(res, true, "rule", "Space usage limit", "%s", StringBuffer_toString(sb)); _displayTableRow(res, true, "rule", "Space usage limit", "%s", StringBuffer_toString(sb));
break; break;
case Resource_SpaceFree: case Resource_SpaceFree:
if (dl->limit_absolute > -1) if (dl->limit_absolute > -1)
Util_printRule(sb, dl->action, "If %s %s", opera tornames[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){})); Util_printRule(false, sb, dl->action, "If %s %s" , operatornames[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){ }));
else else
Util_printRule(sb, dl->action, "If %s %.1f%%", o peratornames[dl->operator], dl->limit_percent); Util_printRule(false, sb, dl->action, "If %s %.1 f%%", operatornames[dl->operator], dl->limit_percent);
_displayTableRow(res, true, "rule", "Space free limit", "%s", StringBuffer_toString(sb)); _displayTableRow(res, true, "rule", "Space free limit", "%s", StringBuffer_toString(sb));
break; break;
case Resource_ReadBytes: case Resource_ReadBytes:
_displayTableRow(res, true, "rule", "Read limit", "%s", StringBuffer_toString(Util_printRule(sb, dl->action, "If read %s %s/s", operator names[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){})))); _displayTableRow(res, true, "rule", "Read limit", "%s", StringBuffer_toString(Util_printRule(false, sb, dl->action, "If read %s %s/s", o peratornames[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){})) ));
break; break;
case Resource_ReadOperations: case Resource_ReadOperations:
_displayTableRow(res, true, "rule", "Read limit", "%s", StringBuffer_toString(Util_printRule(sb, dl->action, "If read %s %llu operations /s", operatornames[dl->operator], dl->limit_absolute))); _displayTableRow(res, true, "rule", "Read limit", "%s", StringBuffer_toString(Util_printRule(false, sb, dl->action, "If read %s %llu ope rations/s", operatornames[dl->operator], dl->limit_absolute)));
break; break;
case Resource_WriteBytes: case Resource_WriteBytes:
_displayTableRow(res, true, "rule", "Write limit", "%s", StringBuffer_toString(Util_printRule(sb, dl->action, "If write %s %s/s", operat ornames[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){})))); _displayTableRow(res, true, "rule", "Write limit", "%s", StringBuffer_toString(Util_printRule(false, sb, dl->action, "If write %s %s/s", operatornames[dl->operator], Convert_bytes2str(dl->limit_absolute, (char[10]){} ))));
break; break;
case Resource_WriteOperations: case Resource_WriteOperations:
_displayTableRow(res, true, "rule", "Write limit", "%s", StringBuffer_toString(Util_printRule(sb, dl->action, "If write %s %llu operatio ns/s", operatornames[dl->operator], dl->limit_absolute))); _displayTableRow(res, true, "rule", "Write limit", "%s", StringBuffer_toString(Util_printRule(false, sb, dl->action, "If write %s %llu o perations/s", operatornames[dl->operator], dl->limit_absolute)));
break; break;
case Resource_ServiceTime: case Resource_ServiceTime:
_displayTableRow(res, true, "rule", "Service time limit" , "%s", StringBuffer_toString(Util_printRule(sb, dl->action, "If service time %s %s/operation", operatornames[dl->operator], Convert_time2str(dl->limit_absolute , (char[11]){})))); _displayTableRow(res, true, "rule", "Service time limit" , "%s", StringBuffer_toString(Util_printRule(false, sb, dl->action, "If service time %s %s/operation", operatornames[dl->operator], Convert_time2str(dl->limit_a bsolute, (char[11]){}))));
break; break;
default: default:
break; break;
} }
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_size(HttpResponse res, Service_T s) { static void print_service_rules_size(HttpResponse res, Service_T s) {
for (Size_T sl = s->sizelist; sl; sl = sl->next) { for (Size_T sl = s->sizelist; sl; sl = sl->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (sl->test_changes) if (sl->test_changes)
Util_printRule(sb, sl->action, "If changed"); Util_printRule(false, sb, sl->action, "If changed");
else else
Util_printRule(sb, sl->action, "If %s %llu byte(s)", ope ratornames[sl->operator], sl->size); Util_printRule(false, sb, sl->action, "If %s %llu byte(s )", operatornames[sl->operator], sl->size);
_displayTableRow(res, true, "rule", "Size", "%s", StringBuffer_t oString(sb)); _displayTableRow(res, true, "rule", "Size", "%s", StringBuffer_t oString(sb));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_linkstatus(HttpResponse res, Service_T s) { static void print_service_rules_linkstatus(HttpResponse res, Service_T s) {
for (LinkStatus_T l = s->linkstatuslist; l; l = l->next) { for (LinkStatus_T l = s->linkstatuslist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Link status", "%s", StringB uffer_toString(Util_printRule(sb, l->action, "If failed"))); _displayTableRow(res, true, "rule", "Link status", "%s", StringB uffer_toString(Util_printRule(l->check_invers, sb, l->action, "If %s", l->check_ invers ? "up" : "down")));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_linkspeed(HttpResponse res, Service_T s) { static void print_service_rules_linkspeed(HttpResponse res, Service_T s) {
for (LinkSpeed_T l = s->linkspeedlist; l; l = l->next) { for (LinkSpeed_T l = s->linkspeedlist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Link capacity", "%s", Strin gBuffer_toString(Util_printRule(sb, l->action, "If changed"))); _displayTableRow(res, true, "rule", "Link capacity", "%s", Strin gBuffer_toString(Util_printRule(false, sb, l->action, "If changed")));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_linksaturation(HttpResponse res, Service_T s) { static void print_service_rules_linksaturation(HttpResponse res, Service_T s) {
for (LinkSaturation_T l = s->linksaturationlist; l; l = l->next) { for (LinkSaturation_T l = s->linksaturationlist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Link saturation", "%s", Str ingBuffer_toString(Util_printRule(sb, l->action, "If %s %.1f%%", operatornames[l ->operator], l->limit))); _displayTableRow(res, true, "rule", "Link saturation", "%s", Str ingBuffer_toString(Util_printRule(false, sb, l->action, "If %s %.1f%%", operator names[l->operator], l->limit)));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_uploadbytes(HttpResponse res, Service_T s) { static void print_service_rules_uploadbytes(HttpResponse res, Service_T s) {
for (Bandwidth_T bl = s->uploadbyteslist; bl; bl = bl->next) { for (Bandwidth_T bl = s->uploadbyteslist; bl; bl = bl->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (bl->range == Time_Second) if (bl->range == Time_Second)
_displayTableRow(res, true, "rule", "Upload bytes", "%s" , StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %s/s", operatornam es[bl->operator], Convert_bytes2str(bl->limit, (char[10]){})))); _displayTableRow(res, true, "rule", "Upload bytes", "%s" , StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s %s/s", oper atornames[bl->operator], Convert_bytes2str(bl->limit, (char[10]){}))));
else else
_displayTableRow(res, true, "rule", "Total upload bytes" , "%s", StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %s in last % d %s(s)", operatornames[bl->operator], Convert_bytes2str(bl->limit, (char[10]){} ), bl->rangecount, Util_timestr(bl->range)))); _displayTableRow(res, true, "rule", "Total upload bytes" , "%s", StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s %s in last %d %s(s)", operatornames[bl->operator], Convert_bytes2str(bl->limit, (char [10]){}), bl->rangecount, Util_timestr(bl->range))));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_uploadpackets(HttpResponse res, Service_T s) { static void print_service_rules_uploadpackets(HttpResponse res, Service_T s) {
for (Bandwidth_T bl = s->uploadpacketslist; bl; bl = bl->next) { for (Bandwidth_T bl = s->uploadpacketslist; bl; bl = bl->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (bl->range == Time_Second) if (bl->range == Time_Second)
_displayTableRow(res, true, "rule", "Upload packets", "% s", StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %lld packets/s", operatornames[bl->operator], bl->limit))); _displayTableRow(res, true, "rule", "Upload packets", "% s", StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s %lld pack ets/s", operatornames[bl->operator], bl->limit)));
else else
_displayTableRow(res, true, "rule", "Total upload packet s", "%s", StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %lld packe ts in last %d %s(s)", operatornames[bl->operator], bl->limit, bl->rangecount, Ut il_timestr(bl->range)))); _displayTableRow(res, true, "rule", "Total upload packet s", "%s", StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s %ll d packets in last %d %s(s)", operatornames[bl->operator], bl->limit, bl->rangeco unt, Util_timestr(bl->range))));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_downloadbytes(HttpResponse res, Service_T s) { static void print_service_rules_downloadbytes(HttpResponse res, Service_T s) {
for (Bandwidth_T bl = s->downloadbyteslist; bl; bl = bl->next) { for (Bandwidth_T bl = s->downloadbyteslist; bl; bl = bl->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (bl->range == Time_Second) if (bl->range == Time_Second)
_displayTableRow(res, true, "rule", "Download bytes", "% s", StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %s/s", operatorn ames[bl->operator], Convert_bytes2str(bl->limit, (char[10]){})))); _displayTableRow(res, true, "rule", "Download bytes", "% s", StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s %s/s", op eratornames[bl->operator], Convert_bytes2str(bl->limit, (char[10]){}))));
else else
_displayTableRow(res, true, "rule", "Total download byte s", "%s", StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %s in last %d %s(s)", operatornames[bl->operator], Convert_bytes2str(bl->limit, (char[10]) {}), bl->rangecount, Util_timestr(bl->range)))); _displayTableRow(res, true, "rule", "Total download byte s", "%s", StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s %s in last %d %s(s)", operatornames[bl->operator], Convert_bytes2str(bl->limit, (ch ar[10]){}), bl->rangecount, Util_timestr(bl->range))));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_downloadpackets(HttpResponse res, Service_T s) { static void print_service_rules_downloadpackets(HttpResponse res, Service_T s) {
for (Bandwidth_T bl = s->downloadpacketslist; bl; bl = bl->next) { for (Bandwidth_T bl = s->downloadpacketslist; bl; bl = bl->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (bl->range == Time_Second) if (bl->range == Time_Second)
_displayTableRow(res, true, "rule", "Download packets", "%s", StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %lld packets/s ", operatornames[bl->operator], bl->limit))); _displayTableRow(res, true, "rule", "Download packets", "%s", StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s %lld pa ckets/s", operatornames[bl->operator], bl->limit)));
else else
_displayTableRow(res, true, "rule", "Total download pack ets", "%s", StringBuffer_toString(Util_printRule(sb, bl->action, "If %s %lld pac kets in last %d %s(s)", operatornames[bl->operator], bl->limit, bl->rangecount, Util_timestr(bl->range)))); _displayTableRow(res, true, "rule", "Total download pack ets", "%s", StringBuffer_toString(Util_printRule(false, sb, bl->action, "If %s % lld packets in last %d %s(s)", operatornames[bl->operator], bl->limit, bl->range count, Util_timestr(bl->range))));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_uptime(HttpResponse res, Service_T s) { static void print_service_rules_uptime(HttpResponse res, Service_T s) {
for (Uptime_T ul = s->uptimelist; ul; ul = ul->next) { for (Uptime_T ul = s->uptimelist; ul; ul = ul->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Uptime", "%s", StringBuffer _toString(Util_printRule(sb, ul->action, "If %s %s", operatornames[ul->operator] , _getUptime(ul->uptime, (char[256]){})))); _displayTableRow(res, true, "rule", "Uptime", "%s", StringBuffer _toString(Util_printRule(false, sb, ul->action, "If %s %s", operatornames[ul->op erator], _getUptime(ul->uptime, (char[256]){}))));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_content(HttpResponse res, Service_T s) { static void print_service_rules_content(HttpResponse res, Service_T s) {
if (s->type != Service_Process) { if (s->type != Service_Process) {
for (Match_T ml = s->matchignorelist; ml; ml = ml->next) { for (Match_T ml = s->matchignorelist; ml; ml = ml->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Ignore content", "% s", StringBuffer_toString(Util_printRule(sb, ml->action, "If content %s \"%s\"", ml->not ? "!=" : "=", ml->match_string))); _displayTableRow(res, true, "rule", "Ignore content", "% s", StringBuffer_toString(Util_printRule(false, sb, ml->action, "If content %s \ "%s\"", ml->not ? "!=" : "=", ml->match_string)));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
for (Match_T ml = s->matchlist; ml; ml = ml->next) { for (Match_T ml = s->matchlist; ml; ml = ml->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "Content match", "%s ", StringBuffer_toString(Util_printRule(sb, ml->action, "If content %s \"%s\"", ml->not ? "!=" : "=", ml->match_string))); _displayTableRow(res, true, "rule", "Content match", "%s ", StringBuffer_toString(Util_printRule(false, sb, ml->action, "If content %s \" %s\"", ml->not ? "!=" : "=", ml->match_string)));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
} }
static void print_service_rules_checksum(HttpResponse res, Service_T s) { static void print_service_rules_checksum(HttpResponse res, Service_T s) {
if (s->checksum) { if (s->checksum) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (s->checksum->test_changes) if (s->checksum->test_changes)
Util_printRule(sb, s->checksum->action, "If changed %s", checksumnames[s->checksum->type]); Util_printRule(false, sb, s->checksum->action, "If chang ed %s", checksumnames[s->checksum->type]);
else else
Util_printRule(sb, s->checksum->action, "If failed %s(%s )", s->checksum->hash, checksumnames[s->checksum->type]); Util_printRule(false, sb, s->checksum->action, "If faile d %s(%s)", s->checksum->hash, checksumnames[s->checksum->type]);
_displayTableRow(res, true, "rule", "Checksum", "%s", StringBuff er_toString(sb)); _displayTableRow(res, true, "rule", "Checksum", "%s", StringBuff er_toString(sb));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_pid(HttpResponse res, Service_T s) { static void print_service_rules_pid(HttpResponse res, Service_T s) {
for (Pid_T l = s->pidlist; l; l = l->next) { for (Pid_T l = s->pidlist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "PID", "%s", StringBuffer_to String(Util_printRule(sb, l->action, "If changed"))); _displayTableRow(res, true, "rule", "PID", "%s", StringBuffer_to String(Util_printRule(false, sb, l->action, "If changed")));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_ppid(HttpResponse res, Service_T s) { static void print_service_rules_ppid(HttpResponse res, Service_T s) {
for (Pid_T l = s->ppidlist; l; l = l->next) { for (Pid_T l = s->ppidlist; l; l = l->next) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
_displayTableRow(res, true, "rule", "PPID", "%s", StringBuffer_t oString(Util_printRule(sb, l->action, "If changed"))); _displayTableRow(res, true, "rule", "PPID", "%s", StringBuffer_t oString(Util_printRule(false, sb, l->action, "If changed")));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
static void print_service_rules_program(HttpResponse res, Service_T s) { static void print_service_rules_program(HttpResponse res, Service_T s) {
if (s->type == Service_Program) { if (s->type == Service_Program) {
_displayTableRow(res, false, "rule", "Program timeout", "Termina te the program if not finished within %s", Convert_time2str(s->program->timeout, (char[11]){})); _displayTableRow(res, false, "rule", "Program timeout", "Termina te the program if not finished within %s", Convert_time2str(s->program->timeout, (char[11]){}));
for (Status_T status = s->statuslist; status; status = status->n ext) { for (Status_T status = s->statuslist; status; status = status->n ext) {
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
if (status->operator == Operator_Changed) if (status->operator == Operator_Changed)
Util_printRule(sb, status->action, "If exit valu e changed"); Util_printRule(false, sb, status->action, "If ex it value changed");
else else
Util_printRule(sb, status->action, "If exit valu e %s %d", operatorshortnames[status->operator], status->return_value); Util_printRule(false, sb, status->action, "If ex it value %s %d", operatorshortnames[status->operator], status->return_value);
_displayTableRow(res, true, "rule", "Test Exit value", " %s", StringBuffer_toString(sb)); _displayTableRow(res, true, "rule", "Test Exit value", " %s", StringBuffer_toString(sb));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
} }
static void print_service_rules_resource(HttpResponse res, Service_T s) { static void print_service_rules_resource(HttpResponse res, Service_T s) {
char buf[STRLEN]; char buf[STRLEN];
for (Resource_T q = s->resourcelist; q; q = q->next) { for (Resource_T q = s->resourcelist; q; q = q->next) {
const char *key = NULL; const char *key = NULL;
skipping to change at line 2296 skipping to change at line 2397
case Resource_CpuSystem: case Resource_CpuSystem:
case Resource_CpuWait: case Resource_CpuWait:
case Resource_CpuNice: case Resource_CpuNice:
case Resource_CpuHardIRQ: case Resource_CpuHardIRQ:
case Resource_CpuSoftIRQ: case Resource_CpuSoftIRQ:
case Resource_CpuSteal: case Resource_CpuSteal:
case Resource_CpuGuest: case Resource_CpuGuest:
case Resource_CpuGuestNice: case Resource_CpuGuestNice:
case Resource_MemoryPercent: case Resource_MemoryPercent:
case Resource_SwapPercent: case Resource_SwapPercent:
Util_printRule(sb, q->action, "If %s %.1f%%", op eratornames[q->operator], q->limit); Util_printRule(false, sb, q->action, "If %s %.1f %%", operatornames[q->operator], q->limit);
break; break;
case Resource_MemoryKbyte: case Resource_MemoryKbyte:
case Resource_SwapKbyte: case Resource_SwapKbyte:
case Resource_MemoryKbyteTotal: case Resource_MemoryKbyteTotal:
Util_printRule(sb, q->action, "If %s %s", operat ornames[q->operator], Convert_bytes2str(q->limit, buf)); Util_printRule(false, sb, q->action, "If %s %s", operatornames[q->operator], Convert_bytes2str(q->limit, buf));
break; break;
case Resource_LoadAverage1m: case Resource_LoadAverage1m:
case Resource_LoadAverage5m: case Resource_LoadAverage5m:
case Resource_LoadAverage15m: case Resource_LoadAverage15m:
case Resource_LoadAveragePerCore1m: case Resource_LoadAveragePerCore1m:
case Resource_LoadAveragePerCore5m: case Resource_LoadAveragePerCore5m:
case Resource_LoadAveragePerCore15m: case Resource_LoadAveragePerCore15m:
Util_printRule(sb, q->action, "If %s %.1f", oper atornames[q->operator], q->limit); Util_printRule(false, sb, q->action, "If %s %.1f ", operatornames[q->operator], q->limit);
break; break;
case Resource_Threads: case Resource_Threads:
case Resource_Children: case Resource_Children:
Util_printRule(sb, q->action, "If %s %.0f", oper atornames[q->operator], q->limit); Util_printRule(false, sb, q->action, "If %s %.0f ", operatornames[q->operator], q->limit);
break; break;
case Resource_ReadBytes: case Resource_ReadBytes:
case Resource_ReadBytesPhysical: case Resource_ReadBytesPhysical:
case Resource_WriteBytes: case Resource_WriteBytes:
case Resource_WriteBytesPhysical: case Resource_WriteBytesPhysical:
Util_printRule(sb, q->action, "if %s %s", operat ornames[q->operator], Convert_bytes2str(q->limit, (char[10]){})); Util_printRule(false, sb, q->action, "if %s %s", operatornames[q->operator], Convert_bytes2str(q->limit, (char[10]){}));
break; break;
case Resource_ReadOperations: case Resource_ReadOperations:
case Resource_WriteOperations: case Resource_WriteOperations:
Util_printRule(sb, q->action, "if %s %.0f operat ions/s", operatornames[q->operator], q->limit); Util_printRule(false, sb, q->action, "if %s %.0f operations/s", operatornames[q->operator], q->limit);
break; break;
default: default:
break; break;
} }
if (key) if (key)
_displayTableRow(res, true, "rule", key, "%s", StringBuf fer_toString(sb)); _displayTableRow(res, true, "rule", key, "%s", StringBuf fer_toString(sb));
StringBuffer_free(&sb); StringBuffer_free(&sb);
} }
} }
skipping to change at line 2365 skipping to change at line 2466
StringBuffer_T sb = StringBuffer_create(256); StringBuffer_T sb = StringBuffer_create(256);
status_xml(sb, NULL, version, Socket_getLocalHost(req->S, buf, s izeof(buf))); status_xml(sb, NULL, version, Socket_getLocalHost(req->S, buf, s izeof(buf)));
StringBuffer_append(res->outputbuffer, "%s", StringBuffer_toStri ng(sb)); StringBuffer_append(res->outputbuffer, "%s", StringBuffer_toStri ng(sb));
StringBuffer_free(&sb); StringBuffer_free(&sb);
set_content_type(res, "text/xml"); set_content_type(res, "text/xml");
} else { } else {
set_content_type(res, "text/plain"); set_content_type(res, "text/plain");
StringBuffer_append(res->outputbuffer, "Monit %s uptime: %s\n\n" , VERSION, _getUptime(ProcessTree_getProcessUptime(getpid()), (char[256]){})); StringBuffer_append(res->outputbuffer, "Monit %s uptime: %s\n\n" , VERSION, _getUptime(ProcessTree_getProcessUptime(getpid()), (char[256]){}));
int found = 0; struct ServiceMap_T ap = {.found = 0, .data.status.res = res};
const char *stringGroup = Util_urlDecode((char *)get_parameter(r eq, "group")); const char *stringGroup = Util_urlDecode((char *)get_parameter(r eq, "group"));
const char *stringService = Util_urlDecode((char *)get_parameter (req, "service")); const char *stringService = Util_urlDecode((char *)get_parameter (req, "service"));
if (stringGroup) { if (stringGroup) {
for (ServiceGroup_T sg = servicegrouplist; sg; sg = sg-> next) { for (ServiceGroup_T sg = servicegrouplist; sg; sg = sg-> next) {
if (IS(stringGroup, sg->name)) { if (IS(stringGroup, sg->name)) {
for (list_t m = sg->members->head; m; m = m->next) { for (list_t m = sg->members->head; m; m = m->next) {
status_service_txt(m->e, res); status_service_txt(m->e, res);
found++; ap.found++;
} }
break; break;
} }
} }
} else { } else {
for (Service_T s = servicelist_conf; s; s = s->next_conf _serviceMapByName(stringService, _serviceMapStatus, &ap)
) { ;
if (! stringService || IS(stringService, s->name
)) {
status_service_txt(s, res);
found++;
}
}
} }
if (found == 0) { if (ap.found == 0) {
if (stringGroup) if (stringGroup)
send_error(req, res, SC_BAD_REQUEST, "Service gr oup '%s' not found", stringGroup); send_error(req, res, SC_BAD_REQUEST, "Service gr oup '%s' not found", stringGroup);
else if (stringService) else if (stringService)
send_error(req, res, SC_BAD_REQUEST, "Service '% s' not found", stringService); send_error(req, res, SC_BAD_REQUEST, "Service '% s' not found", stringService);
else else
send_error(req, res, SC_BAD_REQUEST, "No service found"); send_error(req, res, SC_BAD_REQUEST, "No service found");
} }
} }
} }
static void _printServiceSummary(Box_T t, Service_T s) {
Box_setColumn(t, 1, "%s", s->name);
Box_setColumn(t, 2, "%s", get_service_status(TXT, s, (char[STRLEN]){}, S
TRLEN));
Box_setColumn(t, 3, "%s", servicetypes[s->type]);
Box_printRow(t);
}
static int _printServiceSummaryByType(Box_T t, Service_Type type) {
int found = 0;
for (Service_T s = servicelist_conf; s; s = s->next_conf) {
if (s->type == type) {
_printServiceSummary(t, s);
found++;
}
}
return found;
}
static void print_summary(HttpRequest req, HttpResponse res) { static void print_summary(HttpRequest req, HttpResponse res) {
set_content_type(res, "text/plain"); set_content_type(res, "text/plain");
StringBuffer_append(res->outputbuffer, "Monit %s uptime: %s\n", VERSION, _getUptime(ProcessTree_getProcessUptime(getpid()), (char[256]){})); StringBuffer_append(res->outputbuffer, "Monit %s uptime: %s\n", VERSION, _getUptime(ProcessTree_getProcessUptime(getpid()), (char[256]){}));
int found = 0; struct ServiceMap_T ap = {.found = 0};
const char *stringGroup = Util_urlDecode((char *)get_parameter(req, "gro up")); const char *stringGroup = Util_urlDecode((char *)get_parameter(req, "gro up"));
const char *stringService = Util_urlDecode((char *)get_parameter(req, "s ervice")); const char *stringService = Util_urlDecode((char *)get_parameter(req, "s ervice"));
Box_T t = Box_new(res->outputbuffer, 3, (BoxColumn_T []){
{.name = "Service Name", .width = 31, .wrap = false, .al ap.data.summary.box = TextBox_new(res->outputbuffer, 3, (TextBoxColumn_T
ign = BoxAlign_Left}, []){
{.name = "Status", .width = 26, .wrap = false, .al {.name = "Service Name", .width = 31, .wrap = false, .al
ign = BoxAlign_Left}, ign = TextBoxAlign_Left},
{.name = "Type", .width = 13, .wrap = false, .al {.name = "Status", .width = 26, .wrap = false, .al
ign = BoxAlign_Left} ign = TextBoxAlign_Left},
{.name = "Type", .width = 13, .wrap = false, .al
ign = TextBoxAlign_Left}
}, true); }, true);
if (stringGroup) { if (stringGroup) {
for (ServiceGroup_T sg = servicegrouplist; sg; sg = sg->next) { for (ServiceGroup_T sg = servicegrouplist; sg; sg = sg->next) {
if (IS(stringGroup, sg->name)) { if (IS(stringGroup, sg->name)) {
for (list_t m = sg->members->head; m; m = m->nex t) { for (list_t m = sg->members->head; m; m = m->nex t) {
_printServiceSummary(t, m->e); _printServiceSummary(ap.data.summary.box
found++; , m->e);
ap.found++;
} }
break; break;
} }
} }
} else if (stringService) { } else if (stringService) {
for (Service_T s = servicelist_conf; s; s = s->next_conf) { _serviceMapByName(stringService, _serviceMapSummary, &ap);
if (IS(stringService, s->name)) {
_printServiceSummary(t, s);
found++;
}
}
} else { } else {
found += _printServiceSummaryByType(t, Service_System); _serviceMapByType(Service_System, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_Process); _serviceMapByType(Service_Process, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_File); _serviceMapByType(Service_File, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_Fifo); _serviceMapByType(Service_Fifo, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_Directory); _serviceMapByType(Service_Directory, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_Filesystem); _serviceMapByType(Service_Filesystem, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_Host); _serviceMapByType(Service_Host, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_Net); _serviceMapByType(Service_Net, _serviceMapSummary, &ap);
found += _printServiceSummaryByType(t, Service_Program); _serviceMapByType(Service_Program, _serviceMapSummary, &ap);
} }
Box_free(&t);
if (found == 0) { TextBox_free(&ap.data.summary.box);
if (ap.found == 0) {
if (stringGroup) if (stringGroup)
send_error(req, res, SC_BAD_REQUEST, "Service group '%s' not found", stringGroup); send_error(req, res, SC_BAD_REQUEST, "Service group '%s' not found", stringGroup);
else if (stringService) else if (stringService)
send_error(req, res, SC_BAD_REQUEST, "Service '%s' not f ound", stringService); send_error(req, res, SC_BAD_REQUEST, "Service '%s' not f ound", stringService);
else else
send_error(req, res, SC_BAD_REQUEST, "No service found") ; send_error(req, res, SC_BAD_REQUEST, "No service found") ;
} }
} }
static void _printReport(HttpRequest req, HttpResponse res) { static void _printReport(HttpRequest req, HttpResponse res) {
skipping to change at line 2551 skipping to change at line 2628
StringBuffer_append(res->outputbuffer, "\n"); StringBuffer_append(res->outputbuffer, "\n");
} }
static char *get_monitoring_status(Output_Type type, Service_T s, char *buf, int buflen) { static char *get_monitoring_status(Output_Type type, Service_T s, char *buf, int buflen) {
ASSERT(s); ASSERT(s);
ASSERT(buf); ASSERT(buf);
if (s->monitor == Monitor_Not) { if (s->monitor == Monitor_Not) {
if (type == HTML) if (type == HTML)
snprintf(buf, buflen, "<span class='gray-text'>Not monit ored</span>"); snprintf(buf, buflen, "<span class='gray-text'>Not monit ored</span>");
else else
snprintf(buf, buflen, Color_lightYellow("Not monitored") ); snprintf(buf, buflen, TextColor_lightYellow("Not monitor ed"));
} else if (s->monitor & Monitor_Waiting) { } else if (s->monitor & Monitor_Waiting) {
if (type == HTML) if (type == HTML)
snprintf(buf, buflen, "<span>Waiting</span>"); snprintf(buf, buflen, "<span>Waiting</span>");
else else
snprintf(buf, buflen, Color_white("Waiting")); snprintf(buf, buflen, TextColor_white("Waiting"));
} else if (s->monitor & Monitor_Init) { } else if (s->monitor & Monitor_Init) {
if (type == HTML) if (type == HTML)
snprintf(buf, buflen, "<span class='blue-text'>Initializ ing</span>"); snprintf(buf, buflen, "<span class='blue-text'>Initializ ing</span>");
else else
snprintf(buf, buflen, Color_lightBlue("Initializing")); snprintf(buf, buflen, TextColor_lightBlue("Initializing" ));
} else if (s->monitor & Monitor_Yes) { } else if (s->monitor & Monitor_Yes) {
if (type == HTML) if (type == HTML)
snprintf(buf, buflen, "<span>Monitored</span>"); snprintf(buf, buflen, "<span>Monitored</span>");
else else
snprintf(buf, buflen, "Monitored"); snprintf(buf, buflen, "Monitored");
} }
return buf; return buf;
} }
static char *get_service_status(Output_Type type, Service_T s, char *buf, int bu flen) { static char *get_service_status(Output_Type type, Service_T s, char *buf, int bu flen) {
ASSERT(s); ASSERT(s);
ASSERT(buf); ASSERT(buf);
if (s->monitor == Monitor_Not || s->monitor & Monitor_Init) { if (s->monitor == Monitor_Not || s->monitor & Monitor_Init) {
get_monitoring_status(type, s, buf, buflen); get_monitoring_status(type, s, buf, buflen);
} else if (s->error == 0) { } else if (s->error == 0) {
snprintf(buf, buflen, type == HTML ? "<span class='green-text'>O K</span>" : Color_lightGreen("OK")); snprintf(buf, buflen, type == HTML ? "<span class='green-text'>O K</span>" : TextColor_lightGreen("OK"));
} else { } else {
// In the case that the service has actually some failure, the e rror bitmap will be non zero // In the case that the service has actually some failure, the e rror bitmap will be non zero
char *p = buf; char *p = buf;
EventTable_T *et = Event_Table; EventTable_T *et = Event_Table;
while ((*et).id) { while ((*et).id) {
if (s->error & (*et).id) { if (s->error & (*et).id) {
bool inverse = false;
if ((*et).id == Event_Link && s->inverseStatus)
inverse = true;
if (p > buf) if (p > buf)
p += snprintf(p, buflen - (p - buf), " | "); p += snprintf(p, buflen - (p - buf), " | ");
if (s->error_hint & (*et).id) { if (s->error_hint & (*et).id) {
if (type == HTML) if (type == HTML)
p += snprintf(p, buflen - (p - b uf), "<span class='orange-text'>%s</span>", (*et).description_changed); p += snprintf(p, buflen - (p - b uf), "<span class='orange-text'>%s</span>", (*et).description_changed);
else else
p += snprintf(p, buflen - (p - b uf), Color_lightYellow("%s", (*et).description_changed)); p += snprintf(p, buflen - (p - b uf), TextColor_lightYellow("%s", (*et).description_changed));
} else { } else {
if (type == HTML) if (type == HTML)
p += snprintf(p, buflen - (p - b uf), "<span class='red-text'>%s</span>", (*et).description_failed); p += snprintf(p, buflen - (p - b uf), "<span class='red-text'>%s</span>", inverse ? (*et).description_succeeded : (*et).description_failed);
else else
p += snprintf(p, buflen - (p - b uf), Color_lightRed("%s", (*et).description_failed)); p += snprintf(p, buflen - (p - b uf), TextColor_lightRed("%s", inverse ? (*et).description_succeeded : (*et).desc ription_failed));
} }
} }
et++; et++;
} }
} }
if (s->doaction) if (s->doaction)
snprintf(buf + strlen(buf), buflen - strlen(buf) - 1, " - %s pen ding", actionnames[s->doaction]); snprintf(buf + strlen(buf), buflen - strlen(buf) - 1, " - %s pen ding", actionnames[s->doaction]);
return buf; return buf;
} }
 End of changes. 106 change blocks. 
215 lines changed or deleted 322 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)