Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Sat Jul 20, 2019 2:31 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Securestack CPU Script
PostPosted: Thu Mar 22, 2007 8:46 am 
Offline
User avatar

Joined: Wed Mar 14, 2007 9:44 am
Posts: 15
Location: Germany
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:
<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:
172.30.4.130  13  18  21


Now I have written (ok, a friend has written for me) a little php-script:
Code:
<?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:
c:/php/php.exe -q c:/inetpub/wwwroot/cacti/scripts/c2cpu_query.php 172.30.4.130
I'll get
Code:
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:
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:
File comment: Sample input file
c2_cpu_liste.txt [103 Bytes]
Downloaded 507 times
cacti_graph_template_enterasys_securestack_cpu.xml [15.78 KiB]
Downloaded 579 times
Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 6:53 am 
Offline
User avatar

Joined: Wed Mar 14, 2007 9:44 am
Posts: 15
Location: Germany
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:
@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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group