Securestack CPU Script

Templates, scripts for templates, scripts and requests for templates.

Moderators: Moderators, Developers

Post Reply
Author
Message
User avatar
Ancalagon
Posts: 15
Joined: Wed Mar 14, 2007 9:44 am
Location: Germany

Securestack CPU Script

#1 Post by Ancalagon » Thu Mar 22, 2007 8:46 am

Hi @all,

I'm new on cacti and I'm new on php. So please have mercy when I'm asking dumb questions...

I have several Enterasys Securestacks to monitor. Interface statistics works great but there is no way to get the cpu-utilization via snmp. So I wrote a little (cmd-)script which connects via telnet to all the securestacks, reads the values for cpu-load and writes them in a text-file. The format of the output-file is:

Code: Select all

<Date/Time as header for debugging purposes>
<ip1>  <5sec4ip1>  <60sec4ip1>  <300sec4ip1>
<ip2>  <5sec4ip2>  <60sec4ip2>  <300sec4ip2>
.
.
.
<ipX>  <5sec4ipX>  <60sec4ipX>  <300sec4ipX>
A typical line in this file would be

Code: Select all

172.30.4.130  13  18  21
Now I have written (ok, a friend has written for me) a little php-script:

Code: Select all

<?php

 /* script c2cpu_query.php */

 $addr = $argv[1];
 $filename = "c:/inetpub/wwwroot/cacti/scripts/c2_cpu_liste.txt";

 $vorhanden=file_exists($filename);
 if($vorhanden) {
   $datei=fopen($filename,"r");
   if($datei) {

     while($data=fgets($datei))
     {
       $daten = explode('  ',$data);                                             
       if($daten[0] == $addr) {
          echo "005sec:".$daten[1]." 060sec:".$daten[2]." 300sec:".$daten[3];
       }
     }
   }


   fclose($datei);
 }
 else echo $filename . " not exists!<br>";
?>

When I call this script from the commandline

Code: Select all

c:/php/php.exe -q c:/inetpub/wwwroot/cacti/scripts/c2cpu_query.php 172.30.4.130
I'll get

Code: Select all

005sec:13 060sec:18 300sec:21
as output.

Now I have defined a data-input method calling this script, data_templates and graph_templates using this. I created a graph for one of my SecureStacks - and get errors in my log:

Code: Select all

03/22/2007 02:25:23 PM - CACTID: Poller[0] Host[93] DS[192] WARNING: Result from SCRIPT not valid. Partial Result: ...
03/22/2007 02:25:23 PM - CACTID: Poller[0] Host[93] ERROR: Empty result [172.30.4.130]: 'c:/php/php.exe -q c:/Inetpub/wwwroot/cacti/scripts/c2cpu_query.php 172.30.4.130'
Where is my mistake?

Regards
Stefan


Sorry for my bad English, it's not my native language...
Attachments
cacti_graph_template_enterasys_securestack_cpu.xml
(15.78 KiB) Downloaded 581 times
c2_cpu_liste.txt
Sample input file
(103 Bytes) Downloaded 508 times

User avatar
Ancalagon
Posts: 15
Joined: Wed Mar 14, 2007 9:44 am
Location: Germany

#2 Post by Ancalagon » Fri Mar 23, 2007 6:53 am

Ok, I gave up with php...

Now I've written a little windows/dos-batch, switched back from cactid -> cmd-php and it worked like a charme.

Here the batch:

Code: Select all

@echo off
set infile=c:\inetpub\wwwroot\cacti\scripts\c2_cpu_liste.txt 

for /f "delims==" %%A in (%infile%) do call :output %1 %%A %%B %%C %%D
goto :eof
:output
if %1==%2 echo 005sec:%3 060sec:%4 300sec:%5
Hmmm.... is there a way to call a windows batch-file with cactid?

Post Reply