Re: [Nagios-devel] New Feature: sorting of service- and hostnames

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
Guest

Re: [Nagios-devel] New Feature: sorting of service- and hostnames

Post by Guest »

This is a multi-part message in MIME format.
--------------050607090300060208020409
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

sorry, forgot the file

there it is, made from current cvs source...


Lars Volker schrieb:

> Hi,
>
> wouldn't it be nice if nagios respectively the status.cgi would be
> able to recognize, if two host- or servicenames are domain names,
> which means dot-separated (like blabla.foo.bar.org.uk) and then sort
> the list in an domain-aware kind of way?
>
> Example:
> current behaviour:
> a.x.org
> a.y.org
> b.x.org
> b.y.org
>
> desired behaviour
> a.x.org
> b.x.org
> a.y.org
> b.y.org
>
> I've written a few lines of code, implementing that feature, but i
> edited the source directly and have never worked with patching stuff.
> So if someone would like to explain, i'll provide a patch. Anyways the
> code is just about 9 lines long, simple hack only, but working. There
> also should be some kind of switch to toggle the behaviour.
>
> Thanks
> Lars
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: Oracle 10g
> Get certified on the hottest thing ever to hit the market... Oracle
> 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
> http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
> _______________________________________________
> Nagios-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/lis ... gios-devel
>


--------------050607090300060208020409
Content-Type: text/plain;
name="nagios.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios.diff"

diff -urN ../nagios-cvs.orig/cgi/status.c ./cgi/status.c
--- ../nagios-cvs.orig/cgi/status.c Wed Mar 24 06:22:03 2004
+++ ./cgi/status.c Wed Apr 28 15:40:39 2004
@@ -3899,7 +3899,7 @@
return FALSE;
}
else if(s_option==SORT_HOSTNAME){
- if(strcasecmp(new_svcstatus->host_name,temp_svcstatus->host_name)host_name,temp_svcstatus->host_name)host_name,temp_svcstatus->host_name)>0)
+ if(str_domain_compare(new_svcstatus->host_name,temp_svcstatus->host_name)>0)
return TRUE;
else
return FALSE;
@@ -4053,7 +4053,7 @@
return FALSE;
}
else if(s_option==SORT_HOSTNAME){
- if(strcasecmp(new_hststatus->host_name,temp_hststatus->host_name)host_name,temp_hststatus->host_name)host_name,temp_hststatus->host_name)>0)
+ if(str_domain_compare(new_hststatus->host_name,temp_hststatus->host_name)>0)
return TRUE;
else
return FALSE;
diff -urN ../nagios-cvs.orig/common/statusdata.c ./common/statusdata.c
--- ../nagios-cvs.orig/common/statusdata.c Thu Aug 28 06:07:36 2003
+++ ./common/statusdata.c Wed Apr 28 17:23:47 2004
@@ -178,6 +178,21 @@
#endif


+int str_domain_compare(char *name_a, char *name_b){
+ char *tmp_a, *tmp_b;
+
+ tmp_a = name_a + strlen(name_a) - 1;
+ tmp_b = name_b + strlen(name_b) - 1;
+
+ while ((tmp_a > name_a || tmp_b > name_b) && strcasecmp(tmp_a,tmp_b) == 0){
+ tmp_a--;
+ tmp_b--;
+ while ((tmp_a > name_a) && *(tmp_a)!=46 ) {tmp_a--;}
+ while ((tmp_b > name_b) && *(tmp_b)!=46 ) {tmp_b--;}
+ }
+
+ return strcasecmp(tmp_a,tmp_b);
+}



@@ -348,7 +363,7 @@
/* add new host status to list, sorted by host name */
last_hoststatus=hoststatus_list;
for(temp_hoststatus=hoststatus_list;temp_hoststatus!=NULL;temp_hoststatus=temp_hoststatus->next){
- if(strcmp(new_hoststatus->host_name,temp_hoststatus->host_name)host_name,temp_hoststatus->host_name)next=temp_hoststatus;
if(temp_hoststatus==hoststatus_list)
hoststatus_list=new_hoststatus;
@@ -431,7 +446,7 @@
last_svcstatus=servicestatus_list;
for(temp_svcstatus=servicestatus_list;temp_svcstatus!=N

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked