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