From 5d7e73c203575f5881c10eafcb73e8b60576695c Mon Sep 17 00:00:00 2001
From: Jonas Meurer <jonas@freesources.org>
Date: Tue, 4 Jun 2013 15:31:26 +0200
Subject: [PATCH] enhance the navbar search: - new config option
 'navbar_search_for_addresses': search for IP addresses   in
 navbar search. - new config option
 'navbar_search_for_aliases': search for host aliaes in  
 navbar search.

---
 cgi/cgiutils.c           |    9 +++++++++
 cgi/status.c             |   23 +++++++++++++++++++++--
 sample-config/cgi.cfg.in |   12 ++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/cgi/cgiutils.c b/cgi/cgiutils.c
index 2b488d6..037a742 100644
--- a/cgi/cgiutils.c
+++ b/cgi/cgiutils.c
@@ -66,6 +66,9 @@ int             enable_splunk_integration = FALSE;
 char            *splunk_url = NULL;
 int             lock_author_names = TRUE;
 
+int             navbar_search_for_addresses = FALSE;
+int             navbar_search_for_aliases = FALSE;
+
 time_t          this_scheduled_log_rotation = 0L;
 time_t          last_scheduled_log_rotation = 0L;
 time_t          next_scheduled_log_rotation = 0L;
@@ -405,6 +408,12 @@ int read_cgi_config_file(const char *filename) {
 
 		else if(!strcmp(var, "use_ssl_authentication"))
 			use_ssl_authentication = (atoi(val) > 0) ? TRUE : FALSE;
+
+		else if(!strcmp(var, "navbar_search_for_addresses"))
+			navbar_search_for_addresses = (atoi(val) > 0) ? TRUE : FALSE;
+
+		else if(!strcmp(var, "navbar_search_for_aliases"))
+			navbar_search_for_aliases = (atoi(val) > 0) ? TRUE : FALSE;
 		}
 
 	for(p = illegal_output_chars; p && *p; p++)
diff --git a/cgi/status.c b/cgi/status.c
index bc75d14..c064cc3 100644
--- a/cgi/status.c
+++ b/cgi/status.c
@@ -56,6 +56,9 @@ extern int suppress_alert_window;
 
 extern int enable_splunk_integration;
 
+extern int navbar_search_for_addresses;
+extern int navbar_search_for_aliases;
+
 extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 
@@ -136,6 +139,7 @@ time_t current_time;
 
 char alert_message[MAX_MESSAGE_BUFFER];
 char *host_name = NULL;
+char *host_address = NULL;
 char *host_filter = NULL;
 char *hostgroup_name = NULL;
 char *servicegroup_name = NULL;
@@ -273,8 +277,15 @@ int main(void) {
 					if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
 						continue;
 					if(!strcmp(host_name, temp_host->address)) {
-						free(host_name);
-						host_name = strdup(temp_host->name);
+						host_address = strdup(temp_host->address);
+						host_filter = malloc(sizeof(char) * (strlen(host_address) * 2 + 3));
+						len = strlen(host_address);
+						for(i = 0; i < len; i++, regex_i++) {
+							host_filter[regex_i] = host_address[i];
+						}
+						host_filter[0] = '^';
+						host_filter[regex_i++] = '$';
+						host_filter[regex_i] = '\0';
 						break;
 						}
 					}
@@ -1553,8 +1564,16 @@ void show_service_detail(void) {
 				show_service = TRUE;
 			else if(host_filter != NULL && 0 == regexec(&preg_hostname, temp_status->host_name, 0, NULL, 0))
 				show_service = TRUE;
+			else if(host_filter != NULL && navbar_search_for_addresses == TRUE && 0 == regexec(&preg_hostname, temp_host->address, 0, NULL, 0))
+				show_service = TRUE;
+			else if(host_filter != NULL && navbar_search_for_aliases == TRUE && 0 == regexec(&preg_hostname, temp_host->alias, 0, NULL, 0))
+				show_service = TRUE;
 			else if(!strcmp(host_name, temp_status->host_name))
 				show_service = TRUE;
+			else if(navbar_search_for_addresses == TRUE && !strcmp(host_name, temp_host->address))
+				show_service = TRUE;
+			else if(navbar_search_for_aliases == TRUE && !strcmp(host_name, temp_host->alias))
+				show_service = TRUE;
 			}
 
 		else if(display_type == DISPLAY_HOSTGROUPS) {
diff --git a/sample-config/cgi.cfg.in b/sample-config/cgi.cfg.in
index 1f0cda9..74c5766 100644
--- a/sample-config/cgi.cfg.in
+++ b/sample-config/cgi.cfg.in
@@ -361,3 +361,15 @@ lock_author_names=1
 
 
 
+
+# NAVIGATION BAR SEARCH OPTIONS
+# The following options allow to configure the navbar search. Default
+# is to search for hostnames. With enabled navbar_search_for_addresses,
+# the navbar search queries IP addresses as well. It's also possible
+# to enable search for aliases by setting navbar_search_for_aliases=1.
+
+navbar_search_for_addresses=1
+navbar_search_for_aliases=1
+
+
+
-- 
1.7.10.4

