Nagios navbar search enhancement (Was: Questions about Nagios quick search)
Jonas Meurer <[email protected]>
| Newsgroups | gmane.network.nagios.user,gmane.network.nagios.devel |
|---|---|
| Message-ID | <[email protected]> |
Hey, I just prepared a patch against git master (commit 758a64). I hope that it helps. Don't hesitate to ask if you've any questions. Also feel free to rename the config options if you don't like the names. The patch is attached. Kind regards, jonas Am 2013-06-03 22:26, schrieb Andreas Ericsson: > Would you care to forward the patch so it applies to Nagios 4 as well? > > Otherwise it's likely to get dropped on the floor I'm afraid. > > On 05/29/2013 06:17 PM, Jonas Meurer wrote: >> Hello, >> >> Am 2013-03-01 09:05, schrieb Andreas Ericsson: >>> On 02/28/2013 10:49 PM, Jonas Meurer wrote: >>>> Am 20.02.2013 16:13, schrieb Jonas Meurer: >>>>> Hello, >>>> >>>> Hey again, >>>> >>>>> we're using Nagios as monitoring system for several hundred >>>>> systems. >>>>> While navigating through hosts and services, recently two questions >>>>> regarding the quick search (in navigation bar) raised: >>>>> >>>>> 1/ Why doesn't nagios search for host aliases as well? Is it >>>>> possible >>>>> to enable alias searching? We're using rather short values for >>>>> host_name, and tend to add information like server position to the >>>>> alias. Thus searching for host_name and alias would be awesome for >>>>> us. >>>>> >>> >>> Today it's not possible to enable alias searching. Patches welcome. >>> If you create one, please use some format that makes it possible to >>> add >>> searching on other fields as well, such as "alias~<regex>" or some >>> such. >>> >>>>> 2/ When searching for IP addresses, only the first match is >>>>> returned. >>>>> In some cases (e.g. NRPE Port forwarding through firewall), several >>>>> hosts have the same IP address. For these cases it's rather >>>>> irritating, >>>>> that only the first matching host is returned. >>>>> >>> >>> Tru dat. Patches welcome. You'll want to find and remove the correct >>> "break" statement, I guess. Other than that it shouldn't be much >>> trouble. >> >> I finally managed to prepare a patch that fixes both shortcomings. It >> adds >> two new configuration options to configure the behavior of the >> navigation >> bar search: search for hostname only, or also for addresses, or also >> for >> aliases. >> >> I reported the patch as feature request at >> http://tracker.nagios.org/view.php?id=459 >> >> Kind regards, >> jonas ------------------------------------------------------------------------------ How ServiceNow helps IT people transform IT departments: 1. A cloud service to automate IT design, transition and operations 2. Dashboards that offer high-level views of enterprise services 3. A single system of record for all IT processes http://p.sf.net/sfu/servicenow-d2d-j _______________________________________________ Nagios-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagios-users ::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. ::: Messages without supporting info will risk being sent to /dev/null
enhance_navbar_search.patch
(text/x-diff, 4.2 KB)
From 5d7e73c203575f5881c10eafcb73e8b60576695c Mon Sep 17 00:00:00 2001 From: Jonas Meurer <[email protected]> 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, ¤t_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