Getting error from MRTG when running external script

12 messages Options
Embed this post
Permalink
Scott S. Heath () Getting error from MRTG when running external script
Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Hey all, I’m new to the list and cutting my teeth on Perl (I’m a Windows/Exchange guy by trade) but seem to be the only person where I work who has setup MRTG successfully and has it monitoring all the routers and switches at each client I deal with on a daily basis.

 

We just installed Exchange 2007 into a multi-site organization, got everything working exchange wise perfectly and now I’ve turned my sites to monitoring it. Since I have MRTG already installed and it’s got that wonderful external scripts option I figured I could write something simple to parse a file and pass the results to MRTG.

 

It works…Sort of.

 

Here is the Perl code:

#!/usr/bin/perl

$FileName = $ARGV[0];

open(queueFile, "$FileName");

my $queueFile = <queueFile>;

$queueFile =~ s/copyqueuelength                  : //gi;

 

print $queueFile;

print "0\n";

print "0\n";

print "CopyQueueLength";

 

The script expects a file with 1 line in it. This file is generated and over written once every 15 minutes with the # changing (hopefully dropping and/or staying at 0) and downloaded from my Exchange 2007 server to me MRTG VM .

CopyQueueLength                  : 200

 

Here is the MRTG config file:

 

Target[exchange]: `/etc/mrtg/scripts/parseExch07.pl /etc/mrtg/scripts/copyqueuelength.txt`

MaxBytes[exchange]: 100000

YLegend[exchange]: Files

Legend1[exchange]: Copy Queue Length

Legend2[exchange]: Replay Queue Length

LegendI[exchange]: Copy Queue Length

LegendO[exchange]: Replay Queue Length

ShortLegend[exchange]: Files

Title[exchange]: Copy Queue Length

Options[exchange]: growright, nopercent, integer, unknaszero

Colours[exchange]: GREEN#00eb0c,BLUE#0000ff,GRAY#AAAAAA,VIOLET#ff00ff

WithPeak[exchange]: ymw

PageTop[exchange]: <H1>Copy queue Length</H1>

 

 

When I run mrtg with this config file I get:

 

readline() on closed filehandle NF at /usr/bin/mrtg line 1311.

 

Any Ideas?

 

Thanks in advance. Once I get this working I’ll be sure to share it as so far I haven’t found an app that will monitor Exchange 2007 SCR queue length.

 

UDI LOGO for subscriber gateway.jpg

 

SCOTT HEATH  | Network Engineer

Elmwood Business Park

#10 Commerce Court, Suite A  | New Orleans, LA  70123

504-523-1466  |   [hidden email] |www.udi.com

________________________________________________________________________

Making it easier

 


Alex van den Bogaerdt-2 () Re: Getting error from MRTG when running external script
Reply Threaded More More options
Print post
Permalink
On Mon, Mar 17, 2008 at 09:39:40PM -0500, Scott S. Heath wrote:

> Here is the Perl code:
>
> #!/usr/bin/perl
> $FileName = $ARGV[0];
> open(queueFile, "$FileName");
> my $queueFile = <queueFile>;
> $queueFile =~ s/copyqueuelength                  : //gi;
>
> print $queueFile;
> print "0\n";
> print "0\n";
> print "CopyQueueLength";


If queueFile equals 200, this script will output:

"2000
0
CopyQueueLength"

whereas you probably want:

"200
0
0
CopyQueueLength
"

Notice: you have three lines with two linefeeds, I wrote four lines with
four linefeeds.

Don't know if that is the problem or not, I just noticed.


Scott S. Heath () Re: Getting error from MRTG when running externalscript
Reply Threaded More More options
Print post
Permalink
Actually I wrestled with that for a while. There is a new line char in
the file and I found it easier to leave in then chomp it.





-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Alex van
den Bogaerdt
Sent: Monday, March 17, 2008 10:56 PM
To: [hidden email]
Subject: Re: [mrtg-developers] Getting error from MRTG when running
externalscript

On Mon, Mar 17, 2008 at 09:39:40PM -0500, Scott S. Heath wrote:

> Here is the Perl code:
>
> #!/usr/bin/perl
> $FileName = $ARGV[0];
> open(queueFile, "$FileName");
> my $queueFile = <queueFile>;
> $queueFile =~ s/copyqueuelength                  : //gi;
>
> print $queueFile;
> print "0\n";
> print "0\n";
> print "CopyQueueLength";


If queueFile equals 200, this script will output:

"2000
0
CopyQueueLength"

whereas you probably want:

"200
0
0
CopyQueueLength
"

Notice: you have three lines with two linefeeds, I wrote four lines with
four linefeeds.

Don't know if that is the problem or not, I just noticed.

_______________________________________________
mrtg-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/mrtg-developers



Alex van den Bogaerdt-2 () Re: Getting error from MRTG when running externalscript
Reply Threaded More More options
Print post
Permalink
On Tue, Mar 18, 2008 at 06:16:25AM -0500, Scott S. Heath wrote:
> Actually I wrestled with that for a while. There is a new line char in
> the file and I found it easier to leave in then chomp it.

I suggest you run the output of your script through "od -tx1" or
similar, and then look for characters that shouldn't be there.

Alternatively: replace the script temporarily with some other
script returning a constant number and see if that makes the
problem disappear.  If not, you need not wast time on debugging
that script, but if the problem is magically solved, you know
you have to remove the problem from your perl script.


Scott S. Heath () Re: Getting error from MRTG when runningexternalscript
Reply Threaded More More options
Print post
Permalink
I replaced the last print line of my code with a hard coded print
statement just printing out just 250,50 and received this error:

readline() on closed filehandle NF at /usr/bin/mrtg line 1311.
Use of uninitialized value in concatenation (.) or string at
/usr/bin/mrtg line 1484.

When I pass this code through od -c I get:
0000000   2   5   0  \n   5   0  \n
0000007

When I pass my original code through od -c I get:
0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e   u
0000020   e   L   e   n   g   t   h  \n
0000030

I'm not sure how to interpret this as I'm brand new to perl.

Thanks!





-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Alex van
den Bogaerdt
Sent: Tuesday, March 18, 2008 9:28 AM
To: [hidden email]
Subject: Re: [mrtg-developers] Getting error from MRTG when
runningexternalscript

On Tue, Mar 18, 2008 at 06:16:25AM -0500, Scott S. Heath wrote:
> Actually I wrestled with that for a while. There is a new line char in
> the file and I found it easier to leave in then chomp it.

I suggest you run the output of your script through "od -tx1" or
similar, and then look for characters that shouldn't be there.

Alternatively: replace the script temporarily with some other
script returning a constant number and see if that makes the
problem disappear.  If not, you need not wast time on debugging
that script, but if the problem is magically solved, you know
you have to remove the problem from your perl script.

_______________________________________________
mrtg-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/mrtg-developers


Alex van den Bogaerdt-2 () Re: Getting error from MRTG when runningexternalscript
Reply Threaded More More options
Print post
Permalink
On Tue, Mar 18, 2008 at 10:26:44AM -0500, Scott S. Heath wrote:

> I replaced the last print line of my code with a hard coded print
> statement just printing out just 250,50 and received this error:
>
> readline() on closed filehandle NF at /usr/bin/mrtg line 1311.
> Use of uninitialized value in concatenation (.) or string at
> /usr/bin/mrtg line 1484.
>
> When I pass this code through od -c I get:
> 0000000   2   5   0  \n   5   0  \n
> 0000007
>
> When I pass my original code through od -c I get:
> 0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e   u
> 0000020   e   L   e   n   g   t   h  \n
> 0000030
>
> I'm not sure how to interpret this as I'm brand new to perl.

Looking good. But where does this final newline come from?


Does your mrtg setup work if you don't use the external program
interface?

Can the mrtg script start your script? (check permissions)


Scott S. Heath () Re: Getting error from MRTG whenrunningexternalscript
Reply Threaded More More options
Print post
Permalink
Alex,
I feel so much better knowing I'm not nuts and that my code does work.

MRTG runs fine w/o the external program interface (got it watching our
router at the datacenter so we can charge customers bandwidth)

I found the last newline and removed it.

0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e   u
0000020   e   L   e   n   g   t   h
0000027

The script has 777 permissions (I'll adjust these later) and I still get
the same error.



-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Alex van
den Bogaerdt
Sent: Tuesday, March 18, 2008 10:42 AM
To: [hidden email]
Subject: Re: [mrtg-developers] Getting error from MRTG
whenrunningexternalscript

On Tue, Mar 18, 2008 at 10:26:44AM -0500, Scott S. Heath wrote:

> I replaced the last print line of my code with a hard coded print
> statement just printing out just 250,50 and received this error:
>
> readline() on closed filehandle NF at /usr/bin/mrtg line 1311.
> Use of uninitialized value in concatenation (.) or string at
> /usr/bin/mrtg line 1484.
>
> When I pass this code through od -c I get:
> 0000000   2   5   0  \n   5   0  \n
> 0000007
>
> When I pass my original code through od -c I get:
> 0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e
u
> 0000020   e   L   e   n   g   t   h  \n
> 0000030
>
> I'm not sure how to interpret this as I'm brand new to perl.

Looking good. But where does this final newline come from?


Does your mrtg setup work if you don't use the external program
interface?

Can the mrtg script start your script? (check permissions)

_______________________________________________
mrtg-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/mrtg-developers



Alex van den Bogaerdt-2 () Re: Getting error from MRTG whenrunningexternalscript
Reply Threaded More More options
Print post
Permalink
On Tue, Mar 18, 2008 at 10:57:22AM -0500, Scott S. Heath wrote:

> Alex,
> I feel so much better knowing I'm not nuts and that my code does work.
>
> MRTG runs fine w/o the external program interface (got it watching our
> router at the datacenter so we can charge customers bandwidth)
>
> I found the last newline and removed it.
>
> 0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e   u
> 0000020   e   L   e   n   g   t   h
> 0000027

I didn't imply that you should remove that newline.  I think it is
better to keep it in.  I was just wondering why the output did have
a newline but your code did not show this.

> The script has 777 permissions (I'll adjust these later) and I still get
> the same error.

In this case I have only one suggestion left, if that doesn't work
then someone else will have to step in:

What version of mrtg are you using, maybe you should upgrade or, if
you use the latest version, try one version below.

good luck with your problem.
Alex


Scott S. Heath () Re: Getting error from MRTGwhenrunningexternalscript
Reply Threaded More More options
Print post
Permalink
I think you hit the nail on the head...I copied the script onto one of
my customers VMs and it ran fine.

Well fine is relitive. It runs now but the output on the graphs (and the
numbers below) are all 0.



-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Alex van
den Bogaerdt
Sent: Tuesday, March 18, 2008 4:51 PM
To: [hidden email]
Subject: Re: [mrtg-developers] Getting error from
MRTGwhenrunningexternalscript

On Tue, Mar 18, 2008 at 10:57:22AM -0500, Scott S. Heath wrote:
> Alex,
> I feel so much better knowing I'm not nuts and that my code does work.
>
> MRTG runs fine w/o the external program interface (got it watching our
> router at the datacenter so we can charge customers bandwidth)
>
> I found the last newline and removed it.
>
> 0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e
u
> 0000020   e   L   e   n   g   t   h
> 0000027

I didn't imply that you should remove that newline.  I think it is
better to keep it in.  I was just wondering why the output did have
a newline but your code did not show this.

> The script has 777 permissions (I'll adjust these later) and I still
get
> the same error.

In this case I have only one suggestion left, if that doesn't work
then someone else will have to step in:

What version of mrtg are you using, maybe you should upgrade or, if
you use the latest version, try one version below.

good luck with your problem.
Alex

_______________________________________________
mrtg-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/mrtg-developers



Scott S. Heath () Re: Getting error from MRTGwhenrunningexternalscript
Reply Threaded More More options
Print post
Permalink
In reply to this post by Alex van den Bogaerdt-2
Oh, as far as verion, I forgot I had installed the 95%tile "patch" on
that box. So it looks like it's either the 95%/total bandwidth or
exchange monitoring.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Alex van
den Bogaerdt
Sent: Tuesday, March 18, 2008 4:51 PM
To: [hidden email]
Subject: Re: [mrtg-developers] Getting error from
MRTGwhenrunningexternalscript

On Tue, Mar 18, 2008 at 10:57:22AM -0500, Scott S. Heath wrote:
> Alex,
> I feel so much better knowing I'm not nuts and that my code does work.
>
> MRTG runs fine w/o the external program interface (got it watching our
> router at the datacenter so we can charge customers bandwidth)
>
> I found the last newline and removed it.
>
> 0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e
u
> 0000020   e   L   e   n   g   t   h
> 0000027

I didn't imply that you should remove that newline.  I think it is
better to keep it in.  I was just wondering why the output did have
a newline but your code did not show this.

> The script has 777 permissions (I'll adjust these later) and I still
get
> the same error.

In this case I have only one suggestion left, if that doesn't work
then someone else will have to step in:

What version of mrtg are you using, maybe you should upgrade or, if
you use the latest version, try one version below.

good luck with your problem.
Alex

_______________________________________________
mrtg-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/mrtg-developers



Scott S. Heath () Re: Getting error from MRTGwhenrunningexternalscript
Reply Threaded More More options
Print post
Permalink
In reply to this post by Alex van den Bogaerdt-2
Ok, I've got numbers now on the page but they aren't what I have in the
file. I'm sure MRTG is doing some kind of math against the input but I'm
not sure what it is.

If I knew I could compensate for it in my Perl script. Is there an
option to have it report the raw numbers?





-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Alex van
den Bogaerdt
Sent: Tuesday, March 18, 2008 4:51 PM
To: [hidden email]
Subject: Re: [mrtg-developers] Getting error from
MRTGwhenrunningexternalscript

On Tue, Mar 18, 2008 at 10:57:22AM -0500, Scott S. Heath wrote:
> Alex,
> I feel so much better knowing I'm not nuts and that my code does work.
>
> MRTG runs fine w/o the external program interface (got it watching our
> router at the datacenter so we can charge customers bandwidth)
>
> I found the last newline and removed it.
>
> 0000000   2   0   0  \n   0  \n   0  \n   C   o   p   y   Q   u   e
u
> 0000020   e   L   e   n   g   t   h
> 0000027

I didn't imply that you should remove that newline.  I think it is
better to keep it in.  I was just wondering why the output did have
a newline but your code did not show this.

> The script has 777 permissions (I'll adjust these later) and I still
get
> the same error.

In this case I have only one suggestion left, if that doesn't work
then someone else will have to step in:

What version of mrtg are you using, maybe you should upgrade or, if
you use the latest version, try one version below.

good luck with your problem.
Alex

_______________________________________________
mrtg-developers mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/mrtg-developers



Alex van den Bogaerdt-2 () Re: Getting error from MRTGwhenrunningexternalscript
Reply Threaded More More options
Print post
Permalink
On Tue, Mar 18, 2008 at 05:21:40PM -0500, Scott S. Heath wrote:
> Ok, I've got numbers now on the page but they aren't what I have in the
> file. I'm sure MRTG is doing some kind of math against the input but I'm
> not sure what it is.
>
> If I knew I could compensate for it in my Perl script. Is there an
> option to have it report the raw numbers?

So far I had doubt but now I know for sure: this really belongs on
the mrtg users mailing list.  A lot more people will see your question
and can help. Also make sure to search the mailing list archives.
See http://oss.oetiker.ch/mrtg/support/index.en.html

Look in the docs for gauge and absolute.
See http://oss.oetiker.ch/mrtg/doc/mrtg-reference.en.html

Also see my site.  It is about RRDtool but a lot does also apply
more or less to MRTG.  Especially read the part about rates,
normalization and consolidation.  Things may work a little bit
different in MRTG but it is mostly the same.

Last but not least:  0.99 per second is truncated to 0 in MRTG,
1.99 is truncated to 1, and so on.  So if you have just one error
in 300 seconds (5 minutes), it won't show up.

HTH
--
Alex van den Bogaerdt
http://www.vandenbogaerdt.nl/rrdtool/