check_cluster expand status

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
rbrel
Posts: 3
Joined: Mon Jul 03, 2017 3:57 am

check_cluster expand status

Post by rbrel »

Hi all

Is it possible an option to check_cluster to separate all 'nonok' status ?

Best regards
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: check_cluster expand status

Post by tmcdonald »

Probably, if you know C and there is a way to check that through whatever API that plugin uses.
Former Nagios employee
rbrel
Posts: 3
Joined: Mon Jul 03, 2017 3:57 am

Re: check_cluster expand status

Post by rbrel »

Hi,

I can propose a patch (like this one)

--- nagios-plugins-2.1.4/plugins/check_cluster.c.orig
+++ nagios-plugins-2.1.4/plugins/check_cluster.c
@@ -54,6 +54,7 @@ char *data_vals=NULL;
char *label=NULL;

int verbose=0;
+int expand=0;

int process_arguments(int,char **);

@@ -123,7 +124,17 @@ int main(int argc, char **argv){

/* return the status of the cluster */
if(check_type==CHECK_SERVICES){
- return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds);
+ if (!expand){
+ return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds);
+ }
+ else{
+ return_code=get_status(total_services_critical, thresholds);
+ if (return_code != STATE_CRITICAL){
+ /* Remove critical threshold before checking if there are WARNING services */
+ set_thresholds(&thresholds, warn_threshold, NULL);
+ return_code = get_status(total_services_warning, thresholds);
+ }
+ }
printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
state_text(return_code), (label==NULL)?"Service cluster":label,
total_services_ok,total_services_warning,
@@ -151,6 +162,7 @@ int process_arguments(int argc, char **a
{"label", required_argument,0,'l'},
{"host", no_argument, 0,'h'},
{"service", no_argument, 0,'s'},
+ {"expand", no_argument, 0,'e'},
{"verbose", no_argument, 0,'v'},
{"version", no_argument, 0,'V'},
{"help", no_argument, 0,'H'},
@@ -163,7 +175,7 @@ int process_arguments(int argc, char **a

while(1){

- c=getopt_long(argc,argv,"hHsvVw:c:d:l:",longopts,&option);
+ c=getopt_long(argc,argv,"hHsevVw:c:d:l:",longopts,&option);

if(c==-1 || c==EOF || c==1)
break;
@@ -194,6 +206,10 @@ int process_arguments(int argc, char **a
label=(char *)strdup(optarg);
break;

+ case 'e': /* expand */
+ expand++;
+ break;
+
case 'v': /* verbose */
verbose++;
break;
@@ -241,6 +257,8 @@ print_help(void)
printf (" %s\n", _("Check host cluster status"));
printf (" %s\n", "-l, --label=STRING");
printf (" %s\n", _("Optional prepended text output (i.e. \"Host cluster\")"));
+ printf (" %s\n", "-e, --expand");
+ printf (" %s\n", _("Details check service cluster status"));
printf (" %s\n", "-w, --warning=THRESHOLD");
printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
printf (" %s\n", _("non-OK state in order to return a WARNING status level"));
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: check_cluster expand status

Post by tmcdonald »

Thanks! Do you have a GitHub account? The easiest way to get this into the codebase would be to submit a Pull Request:

https://github.com/nagios-plugins
Former Nagios employee
Locked