Debian Codegraph @

madrisan-nagios-plugins-linux/nagios-plugins-linux/check_skel.c.sample

raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2020 Davide Madrisan <[email protected]>
5 *
6 * A Nagios plugin that do something ....
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include <getopt.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include "common.h"
28 #include "messages.h"
29 #include "progname.h"
30 #include "progversion.h"
31 #include "thresholds.h"
32
33 static const char *program_copyright =
34 "Copyright (C) 2020 Davide Madrisan <" PACKAGE_BUGREPORT ">\n";
35
36 static struct option const longopts[] = {
37 {(char *) "critical", required_argument, NULL, 'c'},
38 {(char *) "warning", required_argument, NULL, 'w'},
39 {(char *) "verbose", no_argument, NULL, 'v'},
40 {(char *) "help", no_argument, NULL, GETOPT_HELP_CHAR},
41 {(char *) "version", no_argument, NULL, GETOPT_VERSION_CHAR},
42 {NULL, 0, NULL, 0}
43 };
44
45 static _Noreturn void
46 usage (FILE * out)
47 {
48 fprintf (out, "%s (" PACKAGE_NAME ") v%s\n", program_name, program_version);
49 fputs ("This plugin ... .\n", out);
50 fputs (program_copyright, out);
51 fputs (USAGE_HEADER, out);
52 fprintf (out, " %s -w COUNTER|PERC -c COUNTER|PERC\n", program_name);
53 fputs (USAGE_OPTIONS, out);
54 fputs (" -w, --warning COUNTER warning threshold\n", out);
55 fputs (" -c, --critical COUNTER critical threshold\n", out);
56 fputs (" -v, --verbose show details for command-line debugging "
57 "(Nagios may truncate output)\n", out);
58 fputs (USAGE_HELP, out);
59 fputs (USAGE_VERSION, out);
60 fputs (USAGE_EXAMPLES, out);
61 fprintf (out, " %s ... -w ... -c ...\n",
62 program_name);
63
64 exit (out == stderr ? STATE_UNKNOWN : STATE_OK);
65 }
66
67 static _Noreturn void
68 print_version (void)
69 {
70 printf ("%s (" PACKAGE_NAME ") v%s\n", program_name, program_version);
71 fputs (program_copyright, stdout);
72 fputs (GPLv3_DISCLAIMER, stdout);
73
74 exit (STATE_OK);
75 }
76
77 int
78 main (int argc, char **argv)
79 {
80 int c;
81 bool verbose = false;
82 char *critical = NULL, *warning = NULL;
83 nagstatus status = STATE_OK;
84 thresholds *my_threshold = NULL;
85
86 set_program_name (argv[0]);
87
88 while ((c = getopt_long (argc, argv,
89 "c:w:v" GETOPT_HELP_VERSION_STRING,
90 longopts, NULL)) != -1)
91 {
92 switch (c)
93 {
94 default:
95 usage (stderr);
96 case 'c':
97 critical = optarg;
98 break;
99 case 'w':
100 warning = optarg;
101 break;
102 case 'v':
103 verbose = true;
104 break;
105
106 case_GETOPT_HELP_CHAR
107 case_GETOPT_VERSION_CHAR
108
109 }
110 }
111
112 if (verbose)
113 /*ADDME*/;
114
115 status = set_thresholds (&my_threshold, warning, critical);
116 if (status == NP_RANGE_UNPARSEABLE)
117 usage (stderr);
118
119 status = get_status (0/*FIXME*/, my_threshold);
120 free (my_threshold);
121
122 printf ("%s %s - <STATUS-MSG> | <PERFDATA>\n",
123 program_name_short, state_text (status));
124
125 return status;
126 }