diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-03-07 17:38:14 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-03-07 17:38:14 +0200 |
commit | 032fd28c0a1d75fd01571dbf2714fd106fa374c0 (patch) | |
tree | a0ea650a9d95d7357feacf36b96f3322b5614c1b | |
parent | f6769c969ee779c43ab0df18f7388b9d5a307f96 (diff) | |
download | ping903-032fd28c0a1d75fd01571dbf2714fd106fa374c0.tar.gz ping903-032fd28c0a1d75fd01571dbf2714fd106fa374c0.tar.bz2 |
ping903q: new option "-a"
* NEWS: Update.
* README: Update.
* configure.ac: Version 0.5.90
* doc/ping903q.1: Update.
* src/ping903q.c: Disallow the use without arguments.
New option -a: query statistics for "all" monitored IPs.
-rw-r--r-- | NEWS | 34 | ||||
-rw-r--r-- | README | 13 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | doc/ping903q.1 | 16 | ||||
-rw-r--r-- | src/ping903q.c | 74 |
5 files changed, 74 insertions, 65 deletions
@@ -1,8 +1,40 @@ -Ping903 -- history of user-visible changes. 2020-03-06 +Ping903 -- history of user-visible changes. 2020-03-07 See the end of file for copying conditions. Please send Ping903 bug reports to <gray@gnu.org> +Version 0.5.90 (git) + +* Reorganize entry points structure. + +The "/ip" entry point is gone. The "/hosts" entry point accepts query +arguments: (1) select=LIST, which introduces a list of IP addresses +(hostnames) to query and (2) attr=LIST - a list of attributes to return +in each stat object. In both cases, LIST is a comma-separated list of +values. The "select" argument can be used together with explicit host +(/hosts/IP?select=LIST), which is equivalent to /hosts/?select=IP,LIST. + +The "/match" entry point takes the "select" query argument as well. +It returns an array of match objects. Each object contains at least +the following attributes: + + - name: original host name used in the request + - hosts: array of monitored host names or IPs corresponding to that + name, (can be empty). + +If an error occurred (e.g. host name cannot be resolved) the "error" +attribute contains the textual description of the error. + +* ping903q + +The ping903q utility now accepts one or more hostnames or IP addresses +as arguments in all modes, except nagios check. The statistics or +matches for each IP are returned separately. + +Used without arguments, the program issues error message and exits. +To query statistics for all monitored hosts, use the "-a" option. + + Version 0.5, 2020-03-06 * Implement detection of duplicate replies. @@ -70,6 +70,19 @@ You are not required to keep all your IP addresses in a single file. If necessary, you can scatter them among several files and name each of them in a separate ip-list statement. +IP addresses listed in ip-list files form the "immutable" IP list, +called so because it cannot be altered while the program is running. +The REST API allows the user to add any number of IP addresses at +runtime as well as remove any of IP addresses added this way. These +addresses form the "mutable" IP list. Mutable IP list is preserved +across program restarts. + +This means that actually the immutable IP list is optional. You may +choose to keep monitored addresses in an external storage (an SQL +database, for example) and load them dynamically after the daemon +has started. A working example program for adding IP addresses from +a MySQL database is shipped in the examples directory. + Normally, the ip-list file should contain IP addresses of the hosts to monitor. It is OK, however, to use symbolic DNS names, too. If a hostname resolves to a single A record, such usage is equivalent to diff --git a/configure.ac b/configure.ac index ab90ecc..2d89a2e 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ # along with Ping903. If not, see <http://www.gnu.org/licenses/>. AC_PREREQ([2.69]) -AC_INIT([Ping903], [0.5], [gray@gnu.org], +AC_INIT([Ping903], [0.5.90], [gray@gnu.org], [ping903], [https://puszcza.gnu.org.ua/projects/ping903/]) AC_CONFIG_SRCDIR([src/main.c]) diff --git a/doc/ping903q.1 b/doc/ping903q.1 index c724043..84eccee 100644 --- a/doc/ping903q.1 +++ b/doc/ping903q.1 @@ -13,15 +13,15 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with Ping903. If not, see <http://www.gnu.org/licenses/>. -.TH PING903Q 1 "March 6, 2020" "PING903Q" "User Commands" +.TH PING903Q 1 "March 7, 2020" "PING903Q" "User Commands" .SH NAME ping903q \- ping903 query tool .SH SYNOPSIS \fBping903q\fR\ - [\fB\-hVv\fR]\ + [\fB\-ahVv\fR]\ [\fB\-f \fIFILE\fR]\ [\fB\-R \fIREALM\fR]\ - [\fIIP\fR...] + [\fIHOST\fR...] .PP \fBping903q\fR\ [\fB\-N\fR]\ @@ -37,10 +37,9 @@ ping903q \- ping903 query tool [\fB\-R \fIREALM\fR]\ \fB\-m\fR .SH DESCRIPTION -Queries monitoring statistics from the \fBping903\fR daemon. Used -with argumentst (\fIIP\fR...), displays information about the supplied -IP addresses. Used without arguments, displays statistics about all -IP addresses monitored by the running daemon. +Queries the \fBping903\fR daemon for monitoring statistics about the +given \fBHOST\fRs. To obtain information about all monitored hosts, +use the \fB\-a\fR option. .PP By default a one-line summary is displayed, which informs about the IP and its current status ("alive" vs. "not alive"). Additional @@ -117,6 +116,9 @@ monitored by the server, and with code 2 if it is not. If any error is encountered, \fBping903q\fR exits with status \fB3\fR. .SH OPTIONS .TP +\fB\-a\fR +Query statistics for all monitored hosts. +.TP \fB\-f \fIFILE\fR Read configuration from \fIFILE\fR instead of from the default .BR /etc/ping903.conf . diff --git a/src/ping903q.c b/src/ping903q.c index 8b51367..47e2c68 100644 --- a/src/ping903q.c +++ b/src/ping903q.c @@ -784,9 +784,12 @@ static char * argvjoin(int argc, char **argv) { int i; - size_t len = argc - 1; + size_t len; char *ret, *p, *q; - + + if (argc == 0) + return NULL; + len = argc - 1; for (i = 0; i < argc; i++) len += strlen(argv[i]); @@ -1077,52 +1080,6 @@ match_hosts(int argc, char **argv) exit(EX_NAGIOS_CRITICAL); exit(EX_NAGIOS_WARNING); } - -static void -query_all(void) -{ - int rc; - struct http_resp resp; - struct json_value *obj; - char const *hval; - char *p; - size_t count[2] = { 0, 0 }; - size_t len; - size_t i; - - http_resp_init(&resp); - http_query("GET", "/host", std_headers, &resp); - if (resp.code != 200) { - abend("%s", resp.reason); - } - - hval = http_resp_get_header(&resp, "content-type"); - if (!hval || strcmp(hval, "application/json")) { - abend("missing or unsupported content type"); - } - - rc = json_parse_string(resp.content, &obj, &p); - if (rc != JSON_E_NOERR) { - abend("%s near %s", json_strerror(rc), p); - } - if (obj->type != json_array) { - abend("returned entity has wrong type"); - } - len = json_array_length(obj); - for (i = 0; i < len; i++) { - struct json_value *jv; - if (json_array_get(obj, i, &jv)) { - abend("can't get element %lu", (unsigned long) i); - } - if (jv->type == json_object) - count[print_host_status(jv) != EX_NAGIOS_OK]++; - } - if (count[1] == 0) - exit(EX_NAGIOS_OK); - if (count[0] == 0) - exit(EX_NAGIOS_CRITICAL); - exit(EX_NAGIOS_WARNING); -} struct nagios_threshold { double round_trip; @@ -1324,13 +1281,14 @@ query_host_nagios(char const *host, struct nagios_check_data *chkdata) void usage(void) { - printf("Usage: %s [-hrVv] [-f FILE] [HOST...]\n", progname); + printf("Usage: %s [-ahrVv] [-f FILE] [HOST...]\n", progname); printf(" or: %s [-N] [-p PREFIX] -H HOST -c RTA,PCT%% -w RTA,PCT%%\n", progname); printf(" or: %s -m HOST\n", progname); printf("Query ping903 daemon.\n"); printf("\n"); printf("Options:\n\n"); + printf(" -a query statistics for all monitored hosts\n"); printf(" -f FILE read configuration from FILE\n"); printf(" -h print this help test\n"); printf(" -R REALM use credentials for this authentication realm\n"); @@ -1384,6 +1342,7 @@ main(int argc, char **argv) int c; char *p; char const *host = NULL; + int a_opt = 0; char *c_opt = NULL; char *w_opt = NULL; char *realm = NULL; @@ -1401,8 +1360,11 @@ main(int argc, char **argv) exit(0); } } - while ((c = getopt(argc, argv, "c:f:H:hNmp:R:rVvw:")) != EOF) { + while ((c = getopt(argc, argv, "ac:f:H:hNmp:R:rVvw:")) != EOF) { switch (c) { + case 'a': + a_opt = 1; + break; case 'c': c_opt = optarg; setmode(MODE_NAGIOS_CHECK, c); @@ -1451,7 +1413,11 @@ main(int argc, char **argv) switch (mode) { case MODE_DEFAULT: + if (argc == 0 && !a_opt) + abend("either give at least one argument " + "or use -a option"); break; + case MODE_NAGIOS_CHECK: if (argc != 0) { abend("bad number of arguments"); @@ -1466,6 +1432,7 @@ main(int argc, char **argv) abend("warning threshold missing; use -w option"); parse_nagios_threshold(w_opt, &chkdata.wth); break; + case MODE_MATCH: if (argc == 0) abend("-m requires one or more command line arguments"); @@ -1492,12 +1459,7 @@ main(int argc, char **argv) switch (mode) { case MODE_DEFAULT: - switch (argc) { - case 0: - query_all(); - default: - query_hosts(argc, argv); - } + query_hosts(argc, argv); break; case MODE_NAGIOS_CHECK: |