summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_cluster.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c
index d6c4b1c5..72acde2e 100644
--- a/plugins/check_cluster.c
+++ b/plugins/check_cluster.c
@@ -60,11 +60,6 @@ static int verbose = 0;
60static int process_arguments(int /*argc*/, char ** /*argv*/); 60static int process_arguments(int /*argc*/, char ** /*argv*/);
61 61
62int main(int argc, char **argv) { 62int main(int argc, char **argv) {
63 char *ptr;
64 int data_val;
65 int return_code = STATE_OK;
66 thresholds *thresholds = NULL;
67
68 setlocale(LC_ALL, ""); 63 setlocale(LC_ALL, "");
69 bindtextdomain(PACKAGE, LOCALEDIR); 64 bindtextdomain(PACKAGE, LOCALEDIR);
70 textdomain(PACKAGE); 65 textdomain(PACKAGE);
@@ -76,14 +71,16 @@ int main(int argc, char **argv) {
76 usage(_("Could not parse arguments")); 71 usage(_("Could not parse arguments"));
77 } 72 }
78 73
74 thresholds *thresholds = NULL;
79 /* Initialize the thresholds */ 75 /* Initialize the thresholds */
80 set_thresholds(&thresholds, warn_threshold, crit_threshold); 76 set_thresholds(&thresholds, warn_threshold, crit_threshold);
81 if (verbose) { 77 if (verbose) {
82 print_thresholds("check_cluster", thresholds); 78 print_thresholds("check_cluster", thresholds);
83 } 79 }
84 80
81 int data_val;
85 /* check the data values */ 82 /* check the data values */
86 for (ptr = strtok(data_vals, ","); ptr != NULL; ptr = strtok(NULL, ",")) { 83 for (char *ptr = strtok(data_vals, ","); ptr != NULL; ptr = strtok(NULL, ",")) {
87 84
88 data_val = atoi(ptr); 85 data_val = atoi(ptr);
89 86
@@ -121,6 +118,7 @@ int main(int argc, char **argv) {
121 } 118 }
122 } 119 }
123 120
121 int return_code = STATE_OK;
124 /* return the status of the cluster */ 122 /* return the status of the cluster */
125 if (check_type == CHECK_SERVICES) { 123 if (check_type == CHECK_SERVICES) {
126 return_code = get_status(total_services_warning + total_services_unknown + total_services_critical, thresholds); 124 return_code = get_status(total_services_warning + total_services_unknown + total_services_critical, thresholds);
@@ -133,13 +131,10 @@ int main(int argc, char **argv) {
133 total_hosts_up, total_hosts_down, total_hosts_unreachable); 131 total_hosts_up, total_hosts_down, total_hosts_unreachable);
134 } 132 }
135 133
136 return return_code; 134 exit(return_code);
137} 135}
138 136
139int process_arguments(int argc, char **argv) { 137int process_arguments(int argc, char **argv) {
140 int c;
141 char *ptr;
142 int option = 0;
143 static struct option longopts[] = {{"data", required_argument, 0, 'd'}, {"warning", required_argument, 0, 'w'}, 138 static struct option longopts[] = {{"data", required_argument, 0, 'd'}, {"warning", required_argument, 0, 'w'},
144 {"critical", required_argument, 0, 'c'}, {"label", required_argument, 0, 'l'}, 139 {"critical", required_argument, 0, 'c'}, {"label", required_argument, 0, 'l'},
145 {"host", no_argument, 0, 'h'}, {"service", no_argument, 0, 's'}, 140 {"host", no_argument, 0, 'h'}, {"service", no_argument, 0, 's'},
@@ -151,36 +146,31 @@ int process_arguments(int argc, char **argv) {
151 return ERROR; 146 return ERROR;
152 } 147 }
153 148
154 while (1) { 149 int option = 0;
155 150 while (true) {
156 c = getopt_long(argc, argv, "hHsvVw:c:d:l:", longopts, &option); 151 int option_index = getopt_long(argc, argv, "hHsvVw:c:d:l:", longopts, &option);
157 152
158 if (c == -1 || c == EOF || c == 1) { 153 if (option_index == -1 || option_index == EOF || option_index == 1) {
159 break; 154 break;
160 } 155 }
161 156
162 switch (c) { 157 switch (option_index) {
163
164 case 'h': /* host cluster */ 158 case 'h': /* host cluster */
165 check_type = CHECK_HOSTS; 159 check_type = CHECK_HOSTS;
166 break; 160 break;
167
168 case 's': /* service cluster */ 161 case 's': /* service cluster */
169 check_type = CHECK_SERVICES; 162 check_type = CHECK_SERVICES;
170 break; 163 break;
171
172 case 'w': /* warning threshold */ 164 case 'w': /* warning threshold */
173 warn_threshold = strdup(optarg); 165 warn_threshold = strdup(optarg);
174 break; 166 break;
175
176 case 'c': /* warning threshold */ 167 case 'c': /* warning threshold */
177 crit_threshold = strdup(optarg); 168 crit_threshold = strdup(optarg);
178 break; 169 break;
179
180 case 'd': /* data values */ 170 case 'd': /* data values */
181 data_vals = (char *)strdup(optarg); 171 data_vals = strdup(optarg);
182 /* validate data */ 172 /* validate data */
183 for (ptr = data_vals; ptr != NULL; ptr += 2) { 173 for (char *ptr = data_vals; ptr != NULL; ptr += 2) {
184 if (ptr[0] < '0' || ptr[0] > '3') { 174 if (ptr[0] < '0' || ptr[0] > '3') {
185 return ERROR; 175 return ERROR;
186 } 176 }
@@ -192,25 +182,20 @@ int process_arguments(int argc, char **argv) {
192 } 182 }
193 } 183 }
194 break; 184 break;
195
196 case 'l': /* text label */ 185 case 'l': /* text label */
197 label = (char *)strdup(optarg); 186 label = strdup(optarg);
198 break; 187 break;
199
200 case 'v': /* verbose */ 188 case 'v': /* verbose */
201 verbose++; 189 verbose++;
202 break; 190 break;
203
204 case 'V': /* version */ 191 case 'V': /* version */
205 print_revision(progname, NP_VERSION); 192 print_revision(progname, NP_VERSION);
206 exit(STATE_UNKNOWN); 193 exit(STATE_UNKNOWN);
207 break; 194 break;
208
209 case 'H': /* help */ 195 case 'H': /* help */
210 print_help(); 196 print_help();
211 exit(STATE_UNKNOWN); 197 exit(STATE_UNKNOWN);
212 break; 198 break;
213
214 default: 199 default:
215 return ERROR; 200 return ERROR;
216 break; 201 break;