Skip to content
Snippets Groups Projects
Commit c387586d authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Tools.Standalone.check_http: Add support for option --expect.

Support matching against the response status line.
parent da9e27b1
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ constant description = "Check HTTP/HTTPS connectivity to a host."; ...@@ -14,6 +14,7 @@ constant description = "Check HTTP/HTTPS connectivity to a host.";
constant options = ({ constant options = ({
({ "help", Getopt.NO_ARG, ({ "-h", "--help" }) }), ({ "help", Getopt.NO_ARG, ({ "-h", "--help" }) }),
({ "version", Getopt.NO_ARG, ({ "-V", "--version" }) }), ({ "version", Getopt.NO_ARG, ({ "-V", "--version" }) }),
({ "expect", Getopt.HAS_ARG, ({ "-e", "--expect" }) }),
({ "min_ssl", Getopt.HAS_ARG, ({ "-S", "--ssl" }) }), ({ "min_ssl", Getopt.HAS_ARG, ({ "-S", "--ssl" }) }),
({ "min_ttl", Getopt.HAS_ARG, ({ "-C", "--certificate" }) }), ({ "min_ttl", Getopt.HAS_ARG, ({ "-C", "--certificate" }) }),
({ "method", Getopt.HAS_ARG, ({ "-j", "--method" }) }), ({ "method", Getopt.HAS_ARG, ({ "-j", "--method" }) }),
...@@ -32,6 +33,8 @@ int start_time; ...@@ -32,6 +33,8 @@ int start_time;
int cert_min_ttl = -1; // Disabled by default. int cert_min_ttl = -1; // Disabled by default.
array(string) expect = ({});
void display_version() void display_version()
{ {
Stdio.stdout.write("Check HTTP/Pike v%d.%d.%d\n", Stdio.stdout.write("Check HTTP/Pike v%d.%d.%d\n",
...@@ -119,6 +122,28 @@ void request_ok(Protocols.HTTP.Query q) ...@@ -119,6 +122,28 @@ void request_ok(Protocols.HTTP.Query q)
} }
} }
if (sizeof(expect)) {
// Re-create the status line, and match against it.
string status_line =
sprintf("%s %03d %s", q->protocol, q->status, q->status_desc);
foreach(expect, string match) {
if (has_value(status_line, match)) {
Stdio.stdout.write("OK: Success. | %s\n", data);
exit(RET_OK);
}
}
if ((q->status > 399) && (q->status < 500)) {
Stdio.stdout.write("WARNING: Bad status code: %s(%d). | %s\n",
q->status_desc, q->status, data);
exit(RET_WARNING);
}
Stdio.stdout.write("FAIL: Bad status code: %s(%d). | %s\n",
q->status_desc, q->status, data);
exit(RET_CRITICAL);
}
if ((q->status > 499) || (q->status < 100)) { if ((q->status > 499) || (q->status < 100)) {
Stdio.stdout.write("FAIL: Bad status code: %s(%d). | %s\n", Stdio.stdout.write("FAIL: Bad status code: %s(%d). | %s\n",
q->status_desc, q->status, data); q->status_desc, q->status, data);
...@@ -151,6 +176,9 @@ int main(int argc, array(string) argv) ...@@ -151,6 +176,9 @@ int main(int argc, array(string) argv)
case "version": case "version":
display_version(); display_version();
exit(0); exit(0);
case "expect":
expect += opt[1]/",";
break;
case "min_ssl": case "min_ssl":
url->scheme = "https"; url->scheme = "https";
switch(lower_case(opt[1])) { switch(lower_case(opt[1])) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment