Plug-In check_apache_status, traffic

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
A.Cormack
Posts: 103
Joined: Fri Nov 23, 2012 6:32 pm

Re: Plug-In check_apache_status, traffic

Post by A.Cormack »

abrist wrote:Try running it from the cli as user "nagios". Report back.

Code: Select all

su nagios
cd /usr/local/nagios/libexec
./check_apache_traffic -H 192.168.19.136 -v traffic -w 5.0 -c 8.0
bash: ./check_apache_traffic: /usr/bin/perl^M: bad interpreter: no such file or directory
You see, now I have a horrible feeling your now going to say "This plug-in uses a perl function that Nagios no longer supports" and I'm not going to be able to use this plug-in... lol
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Plug-In check_apache_status, traffic

Post by abrist »

hmmm. It does not like your perl or cannot find it. Post teh output of the following command:

Code: Select all

which perl
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Plug-In check_apache_status, traffic

Post by lmiltchev »

Open your plugin in vi, type:

Code: Select all

:set ff?
and hit "Enter". See if it says:

Code: Select all

fileformat=unix
You can change format to unix (if you have to) by running:

Code: Select all

:set ff=unix
BTW, do you see "^M" at the end of the lines?
Be sure to check out our Knowledgebase for helpful articles and solutions!
A.Cormack
Posts: 103
Joined: Fri Nov 23, 2012 6:32 pm

Re: Plug-In check_apache_status, traffic

Post by A.Cormack »

abrist wrote:hmmm. It does not like your perl or cannot find it. Post teh output of the following command:

Code: Select all

which perl

Code: Select all

/usr/bin/perl
Limitchev:

Code: Select all

Fileformat=dos
so i changed to

Code: Select all

Fileformat=unix
The error has now changed,

Code: Select all

(Return code of 255 is out of bounds)
A.Cormack
Posts: 103
Joined: Fri Nov 23, 2012 6:32 pm

Re: Plug-In check_apache_status, traffic

Post by A.Cormack »

Now when running the following command on both Nagios and Root

Code: Select all

./check_apache_traffic -H 192.168.19.136
I receive

Code: Select all

[root@localhost libexec]# ./check_apache_traffic -H 192.168.19.136
Can't modify print in scalar assignment at ./check_apache_traffic line 79, near "}) "
syntax error at ./check_apache_traffic line 79, near "}) "
syntax error at ./check_apache_traffic line 82, near "} else"
syntax error at ./check_apache_traffic line 107, near "/) "
  (Might be a runaway multi-line // string starting on line 106)
syntax error at ./check_apache_traffic line 116, near "}"
syntax error at ./check_apache_traffic line 119, near "}"
Unmatched right curly bracket at ./check_apache_traffic line 120, at end of line
Unmatched right curly bracket at ./check_apache_traffic line 122, at end of line
Execution of ./check_apache_traffic aborted due to compilation errors.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Plug-In check_apache_status, traffic

Post by sreinhardt »

Why don't you go ahead and attach that file here so we can take a look. Likely going to be a whole lot easier.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
A.Cormack
Posts: 103
Joined: Fri Nov 23, 2012 6:32 pm

Re: Plug-In check_apache_status, traffic

Post by A.Cormack »

The check_Apache_Traffic plugin file is as follows..

Code: Select all

#!/usr/bin/perl
 
use Getopt::Std;
 
my %options=();
 getopts("H:v:w:c:",\%options);
 
### CONFIGURATION
 %monitor_type = (
 'traffic' => 'LiB',
 'requests_per_second' => 'LiB',
 'bytes_per_request' => 'LiB',
 'accesses' => 'LiB',
 'bytes_per_second' => 'LiB',
 'idle_worker' => 'HiB',
 'uptime' => 'LiB',
 'current_requests' => 'LiB'
 );
 %critical = ( 'traffic' => '60', #MB
 'requests_per_second' => '6',
 'bytes_per_request' => '1024',
 'accesses' => '100000',
 'bytes_per_second' => '1000',
 'idle_worker' => '50',
 'current_requests' => '150'
 );
 %warning = ( 'traffic' => '50', #MB
 'requests_per_second' => '4',
 'bytes_per_request' => '768',
 'accesses' => '50000',
 'bytes_per_second' => '800',
 'idle_worker' => '150',
 'current_requests' => '70'
 );
 my @pretext = ('APACHE OK','APACHE WARNING','APACHE CRITICAL','APACHE UNKNOWN');
 my $server = $options{'H'};
 my $mon = $options{'v'};
 
$warning{$mon} = $options{'w'} if ($options{'w'});
 $critical{$mon} = $options{'c'} if ($options{'c'});
 
help() if (! $options{'H'});
 
my %data = get_apache_status($server);
 if (! keys(%data)) {
 print $pretext[3].": $server did not deliver information.\n";
 exit(3);
 }
 
if ($mon) {
 ($status,$text) = CheckValue($mon,\%data);
 } else {
 ($status,$text) = CheckAll(\%data);
 }
 
print $pretext[$status].":".$text."\n";
 exit($status);
 
sub CheckAll(\%) {
 my $data = shift();
 my %stati = ();
 my $fin_status = 0;
 foreach my $mon (keys(%monitor_type)) {
 my ($status,$txt) = CheckValue($mon,$data);
 $stati{$status}{$mon} = $txt;
 $fin_status = $status if ($status > $fin_status);
 }
 
if ($fin_status == 2) {
 map{ $text .= " $_"; }keys(%{$stati{2}});
 } elsif ($fin_status == 1) {
 map{ $text .= " $_"; }keys(%{$stati{1}});
 }
 $text .= ' ('.scalar(keys(%{$stati{2}})).'c/'.scalar(keys(%{$stati{1}})).'w/'.scalar(keys(%{$stati{0}})).'o)';
 return($fin_status,$text);
 }
 
sub help() {
 print = $warning{$mon}) {
 # status WARNING for "lower = better"
 $ret = 1;
 } else {
 # status OK for "lower = better"
 $ret = 0;
 }
 } elsif ($monitor_type{$mon} eq 'HiB') { # Higher is better
 if ($$data{$mon} 'STAMPBrowser/1.0');
 my $ua = new LWP::UserAgent;
 my $url = new URI::URL($uri);
 my $req = new HTTP::Request(GET, $url, $hdrs);
 my $resp = $ua->request($req);
 my $code = $resp->content;
 
# Server Version: Apache/2.0.59 (Win32) PHP/5.1.6
 # Server Built: Jul 27 2006 15:55:03
 #
 # Current Time: Friday, 11-Apr-2008 09:16:25 W. Europe Daylight Time
 # Restart Time: Friday, 11-Apr-2008 06:01:18 W. Europe Daylight Time
 # Parent Server Generation: 38
 # Server uptime: 3 hours 15 minutes 7 seconds
 # Total accesses: 30554 - Total Traffic: 4.9 MB
 # 2.61 requests/sec - 439 B/second - 168 B/request
 # 3 requests currently being processed, 597 idle workers
 
my %results = ();
 while ($code =~ /([^bytes
 } elsif ( $line =~ m/.*MB/) {
 $results{'traffic'} = $trafc; # MB->bytes
 } elsif ( $line =~ m/.[kK]B/) {
 $results{'traffic'} = eval( $2 / 1024 ); # MB->bytes
 }
 } elsif ( $line =~ /([\d\.]+) requests\/sec - ([\d\.]+) [k]?B\/second - ([\d\.]+) [k]?B\/request/) {
 $results{'requests_per_second'} = $1;
 $results{'bytes_per_second'} = $2;
 $results{'bytes_per_request'} = $3;
 } elsif ( $line =~ /(\d+) requests currently being processed, (\d+) idle workers/) {
 $results{'current_requests'} = $1;
 $results{'idle_worker'} = $2;
 }
 }
 return(%results);
 } 
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Plug-In check_apache_status, traffic

Post by sreinhardt »

I hate to tell you this, but we are not going to work with that comment\plugin. If you want to work through getting k\m\gB working on the original script, that would be fine. However this one either got mangled when being entered to the comments, due to special characters, or never worked properly. There are just too many errors and without understanding the logic behind what he changed it is not worth it. Let me know if you would like to go back to the original one and correct that.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
A.Cormack
Posts: 103
Joined: Fri Nov 23, 2012 6:32 pm

Re: Plug-In check_apache_status, traffic

Post by A.Cormack »

To be honest, I kind of expected what you've said, so no problems.

If its not too much trouble I would be extremely grateful to get the original script working for kB traffic.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Plug-In check_apache_status, traffic

Post by sreinhardt »

Give this a shot! I basically just took the MB line and duplicated it for GB an kB. At the moment it does not differentiate between them, so while you are at kb, you would be expecting hundreds, as it flips to mb, you will need to lower the warn and crit considerably to make sense. If you really need it, I can make it auto calculate, but I would prefer not to. Definitely let me know if this doesn't work as it should.
You do not have the required permissions to view the files attached to this post.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked