[Nagios-devel] avail.cgi patch to allow CSV output from servicegroups / hostgroups

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

[Nagios-devel] avail.cgi patch to allow CSV output from servicegroups / hostgroups

Post by Guest »

This is a multi-part message in MIME format.
--------------070603090001040509090801
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

Wanted to do some reporting and needed to get availability reports based
on host groups, and after some extreme regexp/wget scripting I decided
it would be simpler to modify the code to actually produce the data I
wanted as opposed to me parsing it out.

So I added some code to generate CSV reports to avail.cgi. As I wrote it
I added a bunch of helper functions (being a sucker for small simple
functions and refactoring) thus things (HTML version of the same) might
be broken, but I hope not.
But since I have changed the HTML output the code is a bit experimental
(I don't have a very good test-base at home, so I'll have to try it out
more at work next week) but it would simplify things if others also
tried things (as I don't really use half of the features in nagios).
Thus I wouldn't incorporate this into the codebase just yet, but
everyone is free to try it. It wont (I hope) mess anything up and if the
numbers check (so check reports before and after and see if the numbers
line up) out then I suppose it works, if not let me know and Ill modify
things...

A few questions:

1, As I did some refactoring (broke out the "print" code) the same
functions could be used for the two existing CSV printers the benefit
would be. A, the code would be "more correct" (as in more things using
the same functions as opposed to everyone reimplementing the same code),
and B, adding/changing the printing/formatting code would be simpler.

2, Would XML-output be useful ?
My initial idea was to produce XML as its quite simple to make PDF:s out
of XML. But I suppose you could do something similar using perl and CSV?
Whats the common way to "hand over" (SLA) reports? I think that HTML is
a bit to "cheep" but I want something that is easy to automate and
pretty much could email PDF:s to the supervisor at regular intervalls.

// Michael Medin

--------------070603090001040509090801
Content-Type: text/plain;
name="avail.c.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="avail.c.patch"

Index: cgi/avail.c
===================================================================
RCS file: /cvsroot/nagios/nagios/cgi/avail.c,v
retrieving revision 1.31
diff -u -r1.31 avail.c
--- cgi/avail.c 17 Jan 2005 17:35:33 -0000 1.31
+++ cgi/avail.c 29 May 2005 12:30:13 -0000
@@ -252,6 +252,8 @@
void document_footer(void);
int process_cgivars(void);

+void printPageHeader();
+


int backtrack_archives=2;
@@ -796,7 +798,8 @@
printf("\n",backtrack_archives);
printf("\n");

- if((display_type==DISPLAY_HOST_AVAIL && show_all_hosts==TRUE) || (display_type==DISPLAY_SERVICE_AVAIL && show_all_services==TRUE)){
+ if((display_type==DISPLAY_HOST_AVAIL && show_all_hosts==TRUE) || (display_type==DISPLAY_SERVICE_AVAIL && show_all_services==TRUE) ||
+ (display_type==DISPLAY_HOSTGROUP_AVAIL) || (display_type==DISPLAY_SERVICEGROUP_AVAIL)){
printf("");
printf("Output in CSV Format:\n");
printf("");
@@ -3414,49 +3417,407 @@
void display_hostgroup_availability(void){
hostgroup *temp_hostgroup;

+ printPageHeader();
+
/* display data for a specific hostgroup */
if(show_all_hostgroups==FALSE){
temp_hostgroup=find_hostgroup(hostgroup_name);
display_specific_hostgroup_availability(temp_hostgroup);
- }
+ }

/* display data for all hostgroups */
else{
for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next)
display_specific_hostgroup_availability(temp_hostgroup);
- }
+ }

return;
- }
-
+}


-/* display availability for a specific hostgroup */
-void display_specific_hostgroup_availability(hostgroup *hg){
- unsigned long total_time;
- unsigned long time_determinate;
- unsigned long time_indeterminate;
- avail_subject *temp_subject;
+void printHostlist(int hasHost

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: michael@medin.name
Locked