nagios_grapher questions/help

I just installed the nagios_grapher, and at the risk of sounding like a real dummy, I’m not sure how to get it to work or what it does exactly. The website is in german, which isn’t my native laguage. I am also very much a newbie with GNU/Linux

My goal was to be able to generate reports for monitoring customers using graphs. Or at the least, view the information in graph format

I installed the NagiosGrapher-1.3-1.noarch.rpm with Yast on my Nagios server which is running SuSE 9.3

I took care of all conflicts and dependencies

I followed the instructions in /usr/share/doc/packages/NagiosGrapher/README.package
[blockquote]

  1. enable inside nagios.cfg:
    process_performance_data=1
    service_perfdata_command=process-service-perfdata

  2. activate this process-service-perfdata command.
    define command {
    command_name process-service-perfdata
    command_line /usr/lib/nagios/nagiosgrapher/fifo_write.pl /var/spool/nagios/ngraph.pipe ‘$HOSTNAME$\t$SERVICEDESC$\t$OUTPUT$\t$PERFDATA$\n’ 3
    }

    The SuSE Nagios-rpm puts them into misccommands.cfg, pls. disable the original command definition in this file.

  3. Create the file /etc/nagios/serviceextinfo.cfg and include it in /etc/nagios/cgi.cfg with “xedtemplate_config_file=/etc/nagios/serviceextinfo.cfg”

  4. Make /etc/nagios/serviceextinfo.cfg writeable for the user NagiosGrapher is running as, for example: “chown daemon /etc/nagios/serviceextinfo.cfg”.

  5. Start NagiosGrapher with /etc/init.d/nagiosgrapher start

  6. Reload Nagios
    [/blockquote]

Here’s what I did

  1. I did this

  2. I did this in miscommands.cfg, but nowhere else, because I didnt see this entry in any other config files. Maybe this is my problem?

3.Did this

4.Not sure about this one. All my other cfg files are listed as -rw-rw-r-- root:root.

5.I ran this as a command and it was successful. Do I need to add this to a config file somewhere?

  1. Reloaded successfully. I know if there are syntax errors, it would have failed

If anyone can shed a little light on what I might’ve done wrong,or any other insight, I would greatly appreciate it.

Actually, it is working (sort of)
If I click on “Service Detail”, there are small graph icons that I can click on to get the information. The graphs are only working for the Ping plugin, but not any others.
Here are the images of the errors I am getting for 'Users" and "Load"
http://img.photobucket.com/albums/v383/ozzcrow1/647abf00.png
http://img.photobucket.com/albums/v383/ozzcrow1/4ae02353.png

Anyone have any ideas?
Thanks

Sorry, that is me above, forgot to login

Never used that app. I’m using nagiostat and it’s instructions are written in English.

Umm…ok…
Does nagiostat create graphs?
My main objective for this is for making custom reports for clients.
Should I uninstal nagios_grapher before trying another program, or does it matter?

You will have to modify some of your nagios files, just as you did with grapher. I doubt that an uninstall is needed. Nagiostat uses rrd graphs, which can look nice, but rrd has a steep learning curve.

Thanks, I was just reading some of the docs. Nagiostat looks like it might be a little more along the lines of what I want.
It seems grapher used rrd also. I’ll probably run into some of the same problems, but it looks as though the documentation may be a little better
Some of the configurations I did with grapher look the same
Thanks again

I think this error depends on the version of RRD. I am using the first version of nagios_grapher (from nagiosexchange). The problem is that RRD doesn’t like having additional spaces in some fields and non escaped Characters.

I had to modify rrd2graph.cgi. If you have the later version (which has the drop down bo:evil: I am working on debugging that, but for the alpha version, this is what I had to do.

in rrd2-graph.cgi, find the line
push (@values, “DEF:”. %$->{graph_value}. “=$path”. “$host/”. $xml_hash->{host}->{$host}->{service}->{$service}->{rrd_file}. “:”. %$->{graph_value}. ":AVERAGE ") unless(%$_->{type} =~ /cdef|gprint|hrule/i);

and remove the additional space after the word AVERAGE so it reads like this:

push (@values, “DEF:”. %$->{graph_value}. “=$path”. “$host/”. $xml_hash->{host}->{$host}->{service}->{$service}->{rrd_file}. “:”. %$->{graph_value}. “:AVERAGE”) unless(%$_->{type} =~ /cdef|gprint|hrule/i);

Next, find the line.
my $date=sprintf("%02d:%02d/%02d.%02d.%04d]",$hour,$min,$mday,$mon,$year+1900);

And add the following so as to escape the imbedded : in the $date field
$date=~s/:/\:/g;

Finally, find the bit that calls RRD

RRDs::graph("-", @options, “-h$height”, “-w$width”,"$start", “–title=$host(”. $xml_hash->{host}->{$host}->
{service}->{$service}->{service_title}. “) - $title Graph”, “-v $x_scale”, @values, @graphs, @prints, “COMM
ENT: NETWAYS GmbH - $date\r”);

The problem with the above is that Immediately after the word COMMENT: is a space. remove the space and remove the \r.

I have this working now, but with the later version (which looks quite different) it’s back, so I shall debug that and post a response.

In my opinion this is the best graphing tool of all of them because it’s logical, easy to configure, and automatically graphs any new services that match the regex’s you define.

I am posting right away in hopes of catching you on
I dont have ":AVERAGE “) in my code at that place, but I do have
”:$type ")
I will remove the space there accordingly, and let you know how if it works out.
Thanks for your help!

EDIT:
I’m also a little unclear on this:
Next, find the line.
my $date=sprintf("%02d:%02d/%02d.%02d.%04d]",$hour,$min,$mday,$mon,$year
+1900);

And add the following so as to escape the imbedded : in the $date field
$date=~s/:/:/g;
Not sure exactly where to add $date=~s/:/:/g;
or what the final line should look like
Edited Wed Nov 02 2005, 01:38PM ]

Ok. You have the newer code I think.
I have just got that working too.

Find the following (there are two places where this exists in rrd2-graph.cgi) This is for th 1.3 version.

    RRDs::graph("-", @options, "-h$height", "-w$width","$start", "--title=$host(". $xml_hash->{host}->{$host}->{service}->{$service}->{service_title}. ") - $title Graph", "-v $x_scale", @values, @graphs, @prints, "COMMENT: NETWAYS GmbH - $date\\r");

Ok, Before this line, insert the following:
chop(@values);

As for the $date, insert that after the line
my $date=sprintf etc etc

Let me know.

regards
Declan

So do I need to do ALL of your suggestions, or now do I just need to follow your latest post?
Just unsure. Thanks for your patience

Sorry, it is confusing.

If you are using the latest 1.3 of nagios_grapher then edit rrd2-graph.cgi as follows:

  1. The “:” in the $date causes a problem for RRD. Find the following line
    my $date=sprintf("%02d:%02d/%02d.%02d.%04d]",$hour,$min,$mday,$mon+1,$year+1900);

Now add this after this line.

$date=~s/:/\:/g;

  1. An extra space is being put on the end of the data type (i.e. AVERAGE, MAX, MIN) which RRD doesn;t like.

Find the two lines that start
RRDs::graph(

and insert the following ABOVE them both.

chop(@values);
eg. so they look like this.

First occurence:
chop(@values);
RRDs::graph("-", @options, “-h$height”, “-w$width”,"$start", "–title=MultiGraph: ". $nmgraph{service_name}, “-v $x_scale”, @values, @graphs, “COMMENT: NETWAYS GmbH - $date\r”);
NagiosGrapher::time_need(type=>‘stop’, msg => $title. ’ drawing multigraph’);

Second Occurence:

    chop(@values);
    RRDs::graph("-", @options, "-h$height", "-w$width","$start", "--title=$host(". $xml_hash->{host}->{$host}->{service}->{$service}->{service_title}. ") - $title Graph", "-v $x_scale", @values, @graphs, @prints, "COMMENT: NETWAYS GmbH -$date\\r");

I hope this helps. I also had to comment out the Authentication lines, but I guess you have that working or have already done this.

Declan

Thanks for your detailed help and patience
I am now getting the same errors as posted before, but I am now also getting them with PING
Here is my rdd2-graph.cgi file

#! /usr/bin/perl -w

rrd2-graph.cgi - Returns an Image from an RRDDB using the ngraph configfile

Copyright © 2004, NETWAYS GmbH, Gerd Mueller, Marius Hein

This program is free software; you can redistribute it and/or

modify it under the terms of the GNU General Public License

as published by the Free Software Foundation; either version 2

of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software

Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

use strict;
use lib ‘/usr/lib/nagios/nagiosgrapher’;
use CGI qw(:standard);
use IO::Handle;
use RRDs;
use XML::Simple;
#use Data::Dumper;
use NagiosGrapher;
use GD;
use Time::Local;

use vars qw (
$path
$rrdtool
$configfile
$height
$width
$host
$service
$title
$end
$start
@lines
@values
@graphs
@prints
%tmp
@blocks
@tmp
$ERR
$x_scale
$page_act
$xml_hash
$filename
$nagios_config
$type
@options
$debug
);

CGI Query Params

$host=param(“host”);
$service=param(“service”);
$title=param(“title”);
$end=param(“end”);
$start=param(“start”);
$width=param(“width”);
$height=param(“height”);
$page_act=param(“act_page”);

$type=uc(param(“type”)) if (defined(param(“type”)));
$type=‘AVERAGE’ unless (defined($type));

Configuration

NagiosGrapher::time_need(type=>‘start’);
NagiosGrapher::read_ngrapher_cfg();
NagiosGrapher::time_need(type=>‘stop’, msg => $title. ’ parsing config’);

NagiosGrapher::time_need(type=>‘start’);
NagiosGrapher::read_ngrapher_def();
NagiosGrapher::time_need(type=>‘stop’, msg => $title. ’ parsing graphs’);

$path=NagiosGrapher::get_ngraphercfg_value(‘rrdpath’);
$configfile=NagiosGrapher::get_ngraphercfg_value(‘ngraphcfg’);
$nagios_config=NagiosGrapher::get_ngraphercfg_value(‘nagios_config’);

makes some error in the Apache LOG …

undef $page_act if (length($page_act) <= 0);

if(!NagiosGrapher::AuthCheck($nagios_config,$host,$ENV{‘REMOTE_USER’})) {
print STDOUT “Content-type: image/png\n”;
print STDOUT “Content-disposition: filename=accessdenied.png\n\n”;
print_error(“Sorry you are not allowed to view this graph!\nYour Nagios System”);
exit 0;
}

Setting up default values…

$start="–start=".$start if(defined($start));
$end="–end=".$end if(defined($end));

$height=255 if (!defined($height) || $height eq “”);
$width=595 if (!defined($width) || $width eq “”);

$x_scale = " ";

@options=(’-aPNG’);

Adding some cool options …

my $rrd_background = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_background’);
push @options, ‘-cBACK#’.$rrd_background if (defined $rrd_background);

my $rrd_font = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_font’);
push @options, ‘-cFONT#’.$rrd_font if (defined $rrd_font);

my $rrd_arrow = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_arrow’);
push @options, ‘-cARROW#’.$rrd_arrow if (defined $rrd_arrow);

my $rrd_frame = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_frame’);
push @options, ‘-cFRAME#’.$rrd_frame if (defined $rrd_frame);

my $rrd_grid = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_grid’);
push @options, ‘-cGRID#’.$rrd_grid if (defined $rrd_grid);
push @options, ‘-cMGRID#’.$rrd_grid if (defined $rrd_grid);

my $rrd_canvas = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_canvas’);
push @options, ‘-cCANVAS#’.$rrd_canvas if (defined $rrd_canvas);

Setting up some date as comment.

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time());
my $date=sprintf("%02d:%02d/%02d.%02d.%04d]",$hour,$min,$mday,$mon+1,$year+1900);$date=~s/:/:/g;

if (NagiosGrapher::get_nmgrapherdef($service)) {
NagiosGrapher::time_need(type=>‘start’);
my (%units, @dsnames);
my $graph_type = ‘’;
my %nmgraph = NagiosGrapher::get_nmgrapherdef($service);
if ($nmgraph{colors}) {
NagiosGrapher::set_colors($nmgraph{colors});
}
$xml_hash = NagiosGrapher::get_ngrapherxml();
while (my($host, $val) = each(%{ $xml_hash->{host} })) {
if ($host =~ m/$nmgraph{hosts}/) {
while (my($key, $service) = each(%{ $val->{service} })) {
if ($service->{service_name} =~ m/$nmgraph{services}/) {
@blocks = NagiosGrapher::get_ngrapherdef($service->{service_name}, ‘graph’);
@blocks = reverse(@blocks) if (defined($nmgraph{order}) && $nmgraph{order} =~ m/reverse/i);

                                    # print Dumper \@blocks;
                                    foreach (@blocks) {
                                    	
                                    		next if(!($_->{graph_value} =~ m/$nmgraph{graph_values}/) and $nmgraph{graph_values} ne "");
                                            
                                            $units{$_->{service_name}} = $_->{graph_units} unless (exists($units{$_->{service_name}}));
                                            
                                            my $dsname = NagiosGrapher::get_random_letters(10);
                                            my $color = NagiosGrapher::get_next_color();
                                            
                                            if ($nmgraph{graph_type} =~ m/line/i) {
                                                    $graph_type = 'LINE2';
                                                    push @values, 'DEF:'. $dsname. '='. $path. $host. '/'. $service->{rrd_file}. ':'. $_->{graph_value}. ':'. $type. ' ';
                                                    push @graphs, $graph_type. ':'. $dsname. $color. ':'. ''. $host. '] '. $_->{graph_legend}. "\\J";
                                            }
                                            elsif ($nmgraph{graph_type} =~ m/stack/i) {
                                                    $graph_type = 'AREA';
                                                    $graph_type = "STACK" if (@graphs >= 1);
                                                    push @dsnames, $dsname;
                                                    push @values, 'DEF:'. $dsname. '='. $path. $host. '/'. $service->{rrd_file}. ':'. $_->{graph_value}. ':'. $type. ' ';
                                                    push @graphs, $graph_type. ':'. $dsname. $color. ':'. ''. $host. '] '. $_->{graph_legend}. "\\J";
                                            }
                                            elsif ($nmgraph{graph_type} =~ m/area/i) {
                                                    $graph_type = 'AREA';
                                                    push @values, 'DEF:'. $dsname. '='. $path. $host. '/'. $service->{rrd_file}. ':'. $_->{graph_value}. ':'. $type. ' ';
                                                    
                                                    my $old_ds = $dsname;
                                                    $dsname = NagiosGrapher::get_random_letters(10);
                                                    
                                                    push @values, 'CDEF:'. $dsname. '='. $old_ds. ' ';
                                                    
                                                    push @graphs, $graph_type. ':'. $old_ds. $color. ':'. ''. $host. '] '. $_->{graph_legend}. "\\J";
                                                    push @graphs, 'LINE1'. ':'. $dsname. '#000000'. " ";
                                            }
                                            
                                    }
                            }
                    }
            }
    }
    
    if ($nmgraph{graph_type} =~ m/stack/i) {
            my $cdef = $dsnames[0]. ',';
            shift (@dsnames);
            $cdef .= join(',+,', @dsnames). ',+';
            
            push @values, 'CDEF:'. 'sum1'. '='. $cdef;
            push @graphs, 'LINE1'. ':'. 'sum1'. '#000000'. " ";
    }
    
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' creating multigraph def\'s');
    
    # print Dumper \@graphs;
    print STDOUT "Content-type: image/png\n";
    my $fname = $nmgraph{service_name};
    $fname =~ s/\s+/_/g;
    print STDOUT "Content-disposition: filename=". $fname."_". $title. ".png\n\n";
    $x_scale = join(' / ', values(%units));
    
    NagiosGrapher::time_need(type=>'start');
    chop(@values);
    RRDs::graph("-", @options, "-h$height", "-w$width","$start", "--title=MultiGraph: ". $nmgraph{service_name}, "-v $x_scale", @values, @graphs, "COMMENT: NETWAYS GmbH - $date\r");
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' drawing multigraph');

}
else {
NagiosGrapher::time_need(type=>‘start’);

    # Parsing the Array...
    @blocks = NagiosGrapher::get_ngrapherdef($service);
    
    # Reading XML from index file...
    $xml_hash = NagiosGrapher::get_ngrapherxml();
    
    # fetch the data...
    if (@blocks > 0) {
        foreach (@blocks) {
            # Paging
            next if ($page_act && !($_->{page} eq $page_act));
            
            # Adding real ds
            push (@values, "DEF:". %$_->{graph_value}. "=$path". "$host/". $xml_hash->{host}->{$host}->{service}->{$service}->{rrd_file}. ":". %$_->{graph_value}. ":$type") unless(exists(%$_->{type}) && %$_->{type} =~ /cdef|gprint|hrule/i);
            push (@graphs, %$_->{rrd_plottype}. ":". %$_->{graph_value}. "#". %$_->{rrd_color}. ":". %$_->{graph_legend}. "\\J") unless ( (exists(%$_->{hide}) && %$_->{hide} =~ /yes/i) || (exists(%$_->{type}) && %$_->{type} =~ /cdef|gprint|hrule/i) );
            
            # Adding CDEF's
            if (exists(%$_->{type}) && %$_->{type} =~ /cdef/i) {
                push(@values, "CDEF:". %$_->{graph_value}. "=". %$_->{graph_calc});
                push(@graphs, %$_->{rrd_plottype}. ":". %$_->{graph_value}. "#". %$_->{rrd_color}. ":". %$_->{graph_legend}. "\\J") unless ( (exists(%$_->{hide}) && %$_->{hide} =~ /yes/i) );
            }
            
            # Adding GPRINTs
            if (exists(%$_->{type}) && %$_->{type} =~ /gprint/i) {
                push(@prints, "GPRINT:". %$_->{print_source}. ":". uc(%$_->{print_function}). ":". %$_->{print_description}. "\\: ". %$_->{print_format}. "\\n");
            }
            
            # Adding HRULEs
            if (exists(%$_->{type}) && %$_->{type} =~ /hrule/i) {
                push(@graphs, "HRULE:". %$_->{hrule_value}. "#". %$_->{rrd_color});
            }
            
            unless (exists(%$_->{type}) && %$_->{type} =~ /gprint/i) {
                $x_scale.=" / " if(defined($x_scale) && $x_scale ne "" && !$x_scale =~ /.*?$_->{graph_units}/i && (%$_->{graph_units} ne ""));
                $x_scale.=%$_->{graph_units} unless ($x_scale =~ /.*?$_->{graph_units}/i);
            }
        }
    }
    
    #VLINES 
    if($start eq "--start=-5400") {
            # mark hours
            push(@graphs, "VRULE:".timelocal(0, 0, $hour, $mday, $mon, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-3600);
            push(@graphs, "VRULE:".timelocal(0, 0, $hour, $mday, $mon, $year)."#FF0000");
            
    } elsif ($start eq "--start=-129600") {
            # mark days
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $mday, $mon, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-86400);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $mday, $mon, $year)."#FF0000");
            
    } elsif ($start eq "--start=-907200") {
            # mark weeks
            my $monday_seconds=($wday-1)*24*60*60;
            my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-$monday_seconds);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $mday, $mon, $year)."#FF0000");
            
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-604800);
            $monday_seconds=($wday-1)*24*60*60;
            my $monday=(localtime(time()-$monday_seconds-604800))[3];
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $monday, $mon, $year)."#FF0000");
            
    } elsif ($start eq "--start=-4017600") {
            # mark month
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, $mon, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-2419200);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, $mon, $year)."#FF0000");
            
            # calendarweek workaround
            push(@options,'--x-grid=DAY:1:WEEK:1:WEEK:1:604800:Week %V');
            
    } elsif ($start eq "--start=-48211200") {
            # mark year
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, 0, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-29030400);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, 0, $year)."#FF0000");
    }
    
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' creating graph def\'s');
    
    # Make the output ...
    STDOUT->autoflush(1);
    print STDOUT "Content-type: image/png\n";
    $filename = $xml_hash->{host}->{$host}->{service}->{$service}->{rrd_file};
    $filename =~ s/\.rrd//i;
    print STDOUT "Content-disposition: filename=". $filename. "_". $title. ".png\n\n";
    
    NagiosGrapher::time_need(type=>'start');
    chop(@values);
    RRDs::graph("-", @options, "-h$height", "-w$width","$start", "--title=$host(". $xml_hash->{host}->{$host}->{service}->{$service}->{service_title}. ") - $title Graph", "-v $x_scale", @values, @graphs, @prints, "COMMENT: NETWAYS GmbH - $date\r");
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' drawing graph');

}

$ERR = RRDs::error;
if ($ERR) {
my $msg;
$msg.= “Some error occured:\n”;
$msg.= “~~~~~~~~~~~~~~~~~~~\n\n”;
$msg.= “RRD Error: $ERR\n”;
$msg.= “Options:\n”;
foreach (@options) {
$msg.= " $\n";
}
$msg.= “Values:\n”;
foreach (@values) {
$msg.= " $
\n";
}
$msg.= “\nGraphs:\n”;
foreach (@graphs) {
$msg.= " $\n";
}
$msg.= “\nGPrints:\n”;
foreach (@prints) {
$msg.= " $
\n";
}
$msg.= “\n$date\n”;
print_error($msg);
}

Default exit and return true

exit (0);

sub print_error {
my ($msg) = @_;
my @lines = split(/\n/,$msg);
my $lheight = @lines;
my $im = new GD::Image($width,13*$lheight);

# allocate some colors
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);       
my $red = $im->colorAllocate(255,0,0);      

# make the background transparent and interlaced
$im->transparent($white);
$im->interlaced('true');
my $line=0;
foreach(@lines) {
	$im->string(gdSmallFont,0,$line,$_,$red);
	$line+=12;
}	
  
binmode STDOUT;
print $im->png;	

}

1;

Thanks again for looking. :slight_smile:

I am using rrd 1.2.11. Also, are you using nagios_grapher in Multigraph mode or single graph ? I confess that I have only tested this with single graphs.

I assume that it is this forum that is removing the double \ , but your config looks fine.

The only other thing you could try, is where it says:

COMMENT: NETWAYS GmbH - $date\r

Change that to read
COMMENT:Graphs

Right I can see the problem:

this forum is stripping off what I wrote.
This line:
$date=~s/:/\:/g;

I will write it out with spaces because the forum is interpretting it, but don’t have any spaces in it.

So the bit that goes after $date=~s/:/\ :/g

i.e. there should be two back-slashes before the second :

Or just remove the $date from the COMMENT: lines.

Sorry

Here goes again:

$date=~s forward-slash colon foward-slash back-slash back-slash colon forward-slash g;

It’s getting late!!

Edited Wed Nov 02 2005, 03:49PM ]

just a tip. When you want us to see a backslash, you have to precead it with a backslash.
Below I type backslashbackslash but you will only see backslash.
\

Edited Thu Nov 03 2005, 06:09AM ]

I find it extremely odd that on a forum where the posting of code is often a necessity, certain characters would get stripped. But I digress…

According to ngraph.cfg, I am using single mode

I forgot to specify, I am using Nagios_Grapher 1.3-2 from the RPM, and rrdtool version 1.0.49. I wanted to upgrade to a later version of rrdtool, but I’m not sure how to do it without an rpm for SuSE

I have tried eveything in the suggestions above, all with the same basic results.
I wonder why my ngraph file has the extension of . ncfg instead of .cfg as in the documentation. If I change the name of the file to ngraph.cfg, I lose the error messages, but I get empty graphs on all services, including PING.

THEN if I then change the references (there are 2) to ngraph.ncfg to ngraph.cfg in my NagiosGrapher.pm, I get graphs with data for PING, but error pages on the other services (Load and Users) Basically back to square one.
When I say “error pages”, I am referring to the errors that are in red in my second post in this thread
In a suggestion above, there was code that referred to :AVERAGE ", which I didnt have
In it’s place, my code had $type "
I removed the space after $type, and got error messages. I also replaced $type " with AVERAGE ", with and without the space, and still got error messages.
It seems that the space is necessary?

Here is my latest code from rrd2-graphs.cgi

Lets assume that where there should be double backslashes in the code, that they ARE indeed there, and the forum is stripping them.

#! /usr/bin/perl -w

rrd2-graph.cgi - Returns an Image from an RRDDB using the ngraph configfile

Copyright © 2004, NETWAYS GmbH, Gerd Mueller, Marius Hein

This program is free software; you can redistribute it and/or

modify it under the terms of the GNU General Public License

as published by the Free Software Foundation; either version 2

of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software

Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

use strict;
use lib ‘/usr/lib/nagios/nagiosgrapher’;
use CGI qw(:standard);
use IO::Handle;
use RRDs;
use XML::Simple;
#use Data::Dumper;
use NagiosGrapher;
use GD;
use Time::Local;

use vars qw (
$path
$rrdtool
$configfile
$height
$width
$host
$service
$title
$end
$start
@lines
@values
@graphs
@prints
%tmp
@blocks
@tmp
$ERR
$x_scale
$page_act
$xml_hash
$filename
$nagios_config
$type
@options
$debug
);

CGI Query Params

$host=param(“host”);
$service=param(“service”);
$title=param(“title”);
$end=param(“end”);
$start=param(“start”);
$width=param(“width”);
$height=param(“height”);
$page_act=param(“act_page”);

$type=uc(param(“type”)) if (defined(param(“type”)));
$type=‘AVERAGE’ unless (defined($type));

Configuration

NagiosGrapher::time_need(type=>‘start’);
NagiosGrapher::read_ngrapher_cfg();
NagiosGrapher::time_need(type=>‘stop’, msg => $title. ’ parsing config’);

NagiosGrapher::time_need(type=>‘start’);
NagiosGrapher::read_ngrapher_def();
NagiosGrapher::time_need(type=>‘stop’, msg => $title. ’ parsing graphs’);

$path=NagiosGrapher::get_ngraphercfg_value(‘rrdpath’);
$configfile=NagiosGrapher::get_ngraphercfg_value(‘ngraphcfg’);
$nagios_config=NagiosGrapher::get_ngraphercfg_value(‘nagios_config’);

makes some error in the Apache LOG …

undef $page_act if (length($page_act) <= 0);

if(!NagiosGrapher::AuthCheck($nagios_config,$host,$ENV{‘REMOTE_USER’})) {
print STDOUT “Content-type: image/png\n”;
print STDOUT “Content-disposition: filename=accessdenied.png\n\n”;
print_error(“Sorry you are not allowed to view this graph!\nYour Nagios System”);
exit 0;
}

Setting up default values…

$start="–start=".$start if(defined($start));
$end="–end=".$end if(defined($end));

$height=255 if (!defined($height) || $height eq “”);
$width=595 if (!defined($width) || $width eq “”);

$x_scale = " ";

@options=(’-aPNG’);

Adding some cool options …

my $rrd_background = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_background’);
push @options, ‘-cBACK#’.$rrd_background if (defined $rrd_background);

my $rrd_font = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_font’);
push @options, ‘-cFONT#’.$rrd_font if (defined $rrd_font);

my $rrd_arrow = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_arrow’);
push @options, ‘-cARROW#’.$rrd_arrow if (defined $rrd_arrow);

my $rrd_frame = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_frame’);
push @options, ‘-cFRAME#’.$rrd_frame if (defined $rrd_frame);

my $rrd_grid = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_grid’);
push @options, ‘-cGRID#’.$rrd_grid if (defined $rrd_grid);
push @options, ‘-cMGRID#’.$rrd_grid if (defined $rrd_grid);

my $rrd_canvas = NagiosGrapher::get_ngraphercfg_value(‘rrd_color_canvas’);
push @options, ‘-cCANVAS#’.$rrd_canvas if (defined $rrd_canvas);

Setting up some date as comment.

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time());
my $date=sprintf("%02d:%02d/%02d.%02d.%04d]",$hour,$min,$mday,$mon+1,$year+1900);

if (NagiosGrapher::get_nmgrapherdef($service)) {
NagiosGrapher::time_need(type=>‘start’);
my (%units, @dsnames);
my $graph_type = ‘’;
my %nmgraph = NagiosGrapher::get_nmgrapherdef($service);
if ($nmgraph{colors}) {
NagiosGrapher::set_colors($nmgraph{colors});
}
$xml_hash = NagiosGrapher::get_ngrapherxml();
while (my($host, $val) = each(%{ $xml_hash->{host} })) {
if ($host =~ m/$nmgraph{hosts}/) {
while (my($key, $service) = each(%{ $val->{service} })) {
if ($service->{service_name} =~ m/$nmgraph{services}/) {
@blocks = NagiosGrapher::get_ngrapherdef($service->{service_name}, ‘graph’);
@blocks = reverse(@blocks) if (defined($nmgraph{order}) && $nmgraph{order} =~ m/reverse/i);

                                    # print Dumper \@blocks;
                                    foreach (@blocks) {
                                    	
                                    		next if(!($_->{graph_value} =~ m/$nmgraph{graph_values}/) and $nmgraph{graph_values} ne "");
                                            
                                            $units{$_->{service_name}} = $_->{graph_units} unless (exists($units{$_->{service_name}}));
                                            
                                            my $dsname = NagiosGrapher::get_random_letters(10);
                                            my $color = NagiosGrapher::get_next_color();
                                            
                                            if ($nmgraph{graph_type} =~ m/line/i) {
                                                    $graph_type = 'LINE2';
                                                    push @values, 'DEF:'. $dsname. '='. $path. $host. '/'. $service->{rrd_file}. ':'. $_->{graph_value}. ':'. $type. ' ';
                                                    push @graphs, $graph_type. ':'. $dsname. $color. ':'. ''. $host. '] '. $_->{graph_legend}. "\\J";
                                            }
                                            elsif ($nmgraph{graph_type} =~ m/stack/i) {
                                                    $graph_type = 'AREA';
                                                    $graph_type = "STACK" if (@graphs >= 1);
                                                    push @dsnames, $dsname;
                                                    push @values, 'DEF:'. $dsname. '='. $path. $host. '/'. $service->{rrd_file}. ':'. $_->{graph_value}. ':'. $type. ' ';
                                                    push @graphs, $graph_type. ':'. $dsname. $color. ':'. ''. $host. '] '. $_->{graph_legend}. "\\J";
                                            }
                                            elsif ($nmgraph{graph_type} =~ m/area/i) {
                                                    $graph_type = 'AREA';
                                                    push @values, 'DEF:'. $dsname. '='. $path. $host. '/'. $service->{rrd_file}. ':'. $_->{graph_value}. ':'. $type. ' ';
                                                    
                                                    my $old_ds = $dsname;
                                                    $dsname = NagiosGrapher::get_random_letters(10);
                                                    
                                                    push @values, 'CDEF:'. $dsname. '='. $old_ds. ' ';
                                                    
                                                    push @graphs, $graph_type. ':'. $old_ds. $color. ':'. ''. $host. '] '. $_->{graph_legend}. "\\J";
                                                    push @graphs, 'LINE1'. ':'. $dsname. '#000000'. " ";
                                            }
                                            
                                    }
                            }
                    }
            }
    }
    
    if ($nmgraph{graph_type} =~ m/stack/i) {
            my $cdef = $dsnames[0]. ',';
            shift (@dsnames);
            $cdef .= join(',+,', @dsnames). ',+';
            
            push @values, 'CDEF:'. 'sum1'. '='. $cdef;
            push @graphs, 'LINE1'. ':'. 'sum1'. '#000000'. " ";
    }
    
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' creating multigraph def\'s');
    
    # print Dumper \@graphs;
    print STDOUT "Content-type: image/png\n";
    my $fname = $nmgraph{service_name};
    $fname =~ s/\s+/_/g;
    print STDOUT "Content-disposition: filename=". $fname."_". $title. ".png\n\n";
    $x_scale = join(' / ', values(%units));
    
    NagiosGrapher::time_need(type=>'start');
    chop(@values);
    RRDs::graph("-", @options, "-h$height", "-w$width","$start", "--title=MultiGraph: ". $nmgraph{service_name}, "-v $x_scale", @values, @graphs, "COMMENT:Graphs");
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' drawing multigraph');

}
else {
NagiosGrapher::time_need(type=>‘start’);

    # Parsing the Array...
    @blocks = NagiosGrapher::get_ngrapherdef($service);
    
    # Reading XML from index file...
    $xml_hash = NagiosGrapher::get_ngrapherxml();
    
    # fetch the data...
    if (@blocks > 0) {
        foreach (@blocks) {
            # Paging
            next if ($page_act && !($_->{page} eq $page_act));
            
            # Adding real ds
            push (@values, "DEF:". %$_->{graph_value}. "=$path". "$host/". $xml_hash->{host}->{$host}->{service}->{$service}->{rrd_file}. ":". %$_->{graph_value}. ":$type ") unless(exists(%$_->{type}) && %$_->{type} =~ /cdef|gprint|hrule/i);
            push (@graphs, %$_->{rrd_plottype}. ":". %$_->{graph_value}. "#". %$_->{rrd_color}. ":". %$_->{graph_legend}. "\\J") unless ( (exists(%$_->{hide}) && %$_->{hide} =~ /yes/i) || (exists(%$_->{type}) && %$_->{type} =~ /cdef|gprint|hrule/i) );
            
            # Adding CDEF's
            if (exists(%$_->{type}) && %$_->{type} =~ /cdef/i) {
                push(@values, "CDEF:". %$_->{graph_value}. "=". %$_->{graph_calc});
                push(@graphs, %$_->{rrd_plottype}. ":". %$_->{graph_value}. "#". %$_->{rrd_color}. ":". %$_->{graph_legend}. "\\J") unless ( (exists(%$_->{hide}) && %$_->{hide} =~ /yes/i) );
            }
            
            # Adding GPRINTs
            if (exists(%$_->{type}) && %$_->{type} =~ /gprint/i) {
                push(@prints, "GPRINT:". %$_->{print_source}. ":". uc(%$_->{print_function}). ":". %$_->{print_description}. "\\: ". %$_->{print_format}. "\\n");
            }
            
            # Adding HRULEs
            if (exists(%$_->{type}) && %$_->{type} =~ /hrule/i) {
                push(@graphs, "HRULE:". %$_->{hrule_value}. "#". %$_->{rrd_color});
            }
            
            unless (exists(%$_->{type}) && %$_->{type} =~ /gprint/i) {
                $x_scale.=" / " if(defined($x_scale) && $x_scale ne "" && !$x_scale =~ /.*?$_->{graph_units}/i && (%$_->{graph_units} ne ""));
                $x_scale.=%$_->{graph_units} unless ($x_scale =~ /.*?$_->{graph_units}/i);
            }
        }
    }
    
    #VLINES 
    if($start eq "--start=-5400") {
            # mark hours
            push(@graphs, "VRULE:".timelocal(0, 0, $hour, $mday, $mon, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-3600);
            push(@graphs, "VRULE:".timelocal(0, 0, $hour, $mday, $mon, $year)."#FF0000");
            
    } elsif ($start eq "--start=-129600") {
            # mark days
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $mday, $mon, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-86400);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $mday, $mon, $year)."#FF0000");
            
    } elsif ($start eq "--start=-907200") {
            # mark weeks
            my $monday_seconds=($wday-1)*24*60*60;
            my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-$monday_seconds);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $mday, $mon, $year)."#FF0000");
            
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-604800);
            $monday_seconds=($wday-1)*24*60*60;
            my $monday=(localtime(time()-$monday_seconds-604800))[3];
            push(@graphs, "VRULE:".timelocal(0, 0, 0, $monday, $mon, $year)."#FF0000");
            
    } elsif ($start eq "--start=-4017600") {
            # mark month
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, $mon, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-2419200);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, $mon, $year)."#FF0000");
            
            # calendarweek workaround
            push(@options,'--x-grid=DAY:1:WEEK:1:WEEK:1:604800:Week %V');
            
    } elsif ($start eq "--start=-48211200") {
            # mark year
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, 0, $year)."#FF0000");
            ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday)=localtime(time()-29030400);
            push(@graphs, "VRULE:".timelocal(0, 0, 0, 1, 0, $year)."#FF0000");
    }
    
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' creating graph def\'s');
    
    # Make the output ...
    STDOUT->autoflush(1);
    print STDOUT "Content-type: image/png\n";
    $filename = $xml_hash->{host}->{$host}->{service}->{$service}->{rrd_file};
    $filename =~ s/\.rrd//i;
    print STDOUT "Content-disposition: filename=". $filename. "_". $title. ".png\n\n";
    
    NagiosGrapher::time_need(type=>'start');
    chop(@values);
    RRDs::graph("-", @options, "-h$height", "-w$width","$start", "--title=$host(". $xml_hash->{host}->{$host}->{service}->{$service}->{service_title}. ") - $title Graph", "-v $x_scale", @values, @graphs, @prints, "COMMENT:Graphs");
    NagiosGrapher::time_need(type=>'stop', msg => $title. ' drawing graph');

}

$ERR = RRDs::error;
if ($ERR) {
my $msg;
$msg.= “Some error occured:\n”;
$msg.= “~~~~~~~~~~~~~~~~~~~\n\n”;
$msg.= “RRD Error: $ERR\n”;
$msg.= “Options:\n”;
foreach (@options) {
$msg.= " $\n";
}
$msg.= “Values:\n”;
foreach (@values) {
$msg.= " $
\n";
}
$msg.= “\nGraphs:\n”;
foreach (@graphs) {
$msg.= " $\n";
}
$msg.= “\nGPrints:\n”;
foreach (@prints) {
$msg.= " $
\n";
}
$msg.= “\n$date\n”;
print_error($msg);
}

Default exit and return true

exit (0);

sub print_error {
my ($msg) = @_;
my @lines = split(/\n/,$msg);
my $lheight = @lines;
my $im = new GD::Image($width,13*$lheight);

# allocate some colors
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);       
my $red = $im->colorAllocate(255,0,0);      

# make the background transparent and interlaced
$im->transparent($white);
$im->interlaced('true');
my $line=0;
foreach(@lines) {
	$im->string(gdSmallFont,0,$line,$_,$red);
	$line+=12;
}	
  
binmode STDOUT;
print $im->png;	

}

1;

Again, thanks for your patience, and I hope I was able to explain everything clearly.
Looking at that code, I might as well be looking at hyroglyphics
Thanks for making it clearer to me
.

I am beginning to suspect that this is a problem with rrdtool… :shock:

Edited Thu Nov 03 2005, 12:48PM ]

I am downloading Suse 10 right now, and am going to try running the latest Nagios and rrdtools

I have run into another problem with multigraphs now. They work on a test system I have at home, but on our live nagios system it breaks, only coming up with an image with a little red cross.

Oh well, more debugging.

Let me just try the double back-slash. I guess I must have to put 4 backslashes in to get two out.

\\