Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


php script for pcmeasure to run in cacti

 
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates
Author Message
cpt_ahab
Cacti User


Joined: 01 Feb 2005
Posts: 60

PostPosted: Tue Apr 19, 2005 3:45 am    Post subject: php script for pcmeasure to run in cacti Reply with quote

Here is a little script to get snmp data from the ethernetbox of pcmeasure.
It is designed to run from cactid.

Code:

<?php
if($argv[1] != '' && $argv[2] != '' && $argv[3] != ''){
   $hip = $argv[1];
   $com = $argv[2];
   $sen = $argv[3];
   $max_sensors = 12;
   if($sen > $max_sensors){
      echo "No Data from sensor ".($sen).". Number of sensors: ".$max_sensors." ";
   }else{
      $data = snmpget($hip, $com, ".1.3.6.1.4.1.14848.2.1.2.1.5.".$sen);
      $data = $data/10;
      echo "data:".$data;
   }
      
}else{
   echo "Usage: <path2php>\php\cli\php.exe <path2script>\messpc.php <ipAdr> <snmpcommunity> <sensor>"."\n";
   echo "Example: E:\php\cli\php.exe E:/inetpub/mrtgroot/cacti/scripts/messpc.php 192.168.13.250 pub 1";
 }
?>


GreeZ ahab


Last edited by cpt_ahab on Tue Jul 12, 2005 9:28 am; edited 4 times in total
Back to top
mhinti



Joined: 30 Jun 2005
Posts: 3

PostPosted: Thu Jun 30, 2005 9:25 am    Post subject: Reply with quote

hi, thx for the script

Please, can you make also a graph Template for this? I´m new @ cacti und I need to control two measure ethernet boxes.

Thx
Back to top
cpt_ahab
Cacti User


Joined: 01 Feb 2005
Posts: 60

PostPosted: Tue Jul 12, 2005 9:17 am    Post subject: Reply with quote

Here is is...

GreeZ ahab



pcmeasure_tmpl.txt
 Description:
In this Textfile is the xml-code for the cacti graphtemplate of the pc measure-box. Both Humidity and Temperature

Download
 Filename:  pcmeasure_tmpl.txt
 Filesize:  17.23 KB
 Downloaded:  1731 Time(s)

Back to top
lord0815



Joined: 27 Apr 2005
Posts: 8

PostPosted: Wed Feb 21, 2007 5:44 am    Post subject: Reply with quote

Hey there... i dont get this script working...

For me everything looks fine, and the poller cache shows me the following line

Code:
 Data Source: Redheat - EinSensor
RRD: /srv/www/cacti/rra/messpc_data_232.rrd
Action: 1, Script: php /srv/www/cacti/scripts/messpc1.php 172.16.1.1 public 1


In cacti.log i found these entrys in 'DEBUG' mode:

Code:

02/21/2007 01:52:09 AM - CMDPHP: Poller[0] DEBUG: SQL Exec: "insert into poller_item (local_data_id,host_id,action,hostname,   snmp_community,snmp_version,snmp_timeout,snmp_username,snmp_password,snmp_port,rrd_name,rrd_path,   rrd_num,arg1,arg2,arg3) values (232,40,1,'172.16.1.1',   'public','2','500',   '','','161',   'data','/srv/www/cacti/rra/messpc_data_232.rrd',   '1','php /srv/www/cacti/scripts/messpc1.php 172.16.1.1 public 1','','')"


and

Code:
02/21/2007 11:22:34 AM - WEBLOG: Poller[0] CACTI2RRD: /usr/bin/rrdtool graph -  --imgformat=PNG  --start=-86400  --end=-300  --title="Redheat - EinSensor"  --base=1000  --height=120  --width=500  --alt-autoscale-max  --lower-limit=-10  --vertical-label="Temperatur"  --slope-mode  --font TITLE:8:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf  --font AXIS:7:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf  --font LEGEND:7:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf  --font UNIT:7:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf  DEF:a="/srv/www/cacti/rra/messpc_data_232.rrd":data:AVERAGE  LINE3:a#FF3932:"


Each time the poller runs this entry appears in the log but nothing else for this host:

Code:

02/21/2007 12:06:51 PM - CMDPHP: Poller[0] DEBUG: SQL Exec: "update host set  status = '1',  status_event_count = '24429',  status_fail_date = '0000-00-00 00:00:00',  status_rec_date = '0000-00-00 00:00:00',  status_last_error = 'Host did not respond to SNMP',  min_time = '9.99999',  max_time = '0.00000',  cur_time = '0.00000',  avg_time = '0.00000',  total_polls = '24430',  failed_polls = '24430',  availability = '0'  where hostname = '172.16.1.1'"


Where can i start to find the problem??
The graph is still there but with NaN ...

Running the poller cache line

Code:
php /srv/www/cacti/scripts/messpc1.php 172.16.1.1 public 1


print the following output

Code:
data:18


Anyone has same problems or can help me??

Cacti Variables
Version 0.8.6h
Operating System: unix
PHP SNMP Support: yes

Thanks a lot!
Back to top
cpt_ahab
Cacti User


Joined: 01 Feb 2005
Posts: 60

PostPosted: Tue Feb 27, 2007 3:47 am    Post subject: Reply with quote

Hello

Try to run cacti with MEDUIM Logging. DEBUG is too much.

You should see a line like
Code:

02/27/2007 09:41:03 AM - CACTID: Poller[0] Host[110] DS[793] SCRIPT: /usr/bin/php /var/www/html/cacti/scripts/messpc1.php 192.168.xxx.xxx public 5, output: data:19


You can grep the line easyly out of the cacti.log file,
Or just do a text search with you browser, while viewing it.

If you also see a number after the "data:" field then the script is run right.
Then the problem is about putting the data into the database.

Also try to clear the Pollercache.
System Utilities --> Clear Pollercache

greez ahab


edit: always run the php-binary with its full path.
change php to /usr/bin/php or wherever you php is.
if you dont know run
Code:
whereis php
Back to top
lord0815



Joined: 27 Apr 2005
Posts: 8

PostPosted: Mon Mar 05, 2007 8:38 am    Post subject: Reply with quote

Hey!

Okay, i
Back to top
lord0815



Joined: 27 Apr 2005
Posts: 8

PostPosted: Mon Mar 05, 2007 8:39 am    Post subject: Reply with quote

Hey!

Okay, i
Back to top
lord0815



Joined: 27 Apr 2005
Posts: 8

PostPosted: Mon Mar 05, 2007 8:40 am    Post subject: Reply with quote

Hey!

Okay, i undo all my work for messpc...
Started to import the templates again, created a new device

From this device i get

    SNMP error

Thats okay i think...

Than i created a graph out of the device page

A Look in the Data Source tells me:

    /usr/bin/rrdtool create \
    /srv/www/cacti/rra/messpc_data_235.rrd \
    --step 300 \
    DS:data:GAUGE:600:0:U \
    RRA:AVERAGE:0.5:1:600 \
    RRA:AVERAGE:0.5:6:700 \
    RRA:AVERAGE:0.5:24:775 \
    RRA:AVERAGE:0.5:288:797 \
    RRA:MIN:0.5:1:600 \
    RRA:MIN:0.5:6:700 \
    RRA:MIN:0.5:24:775 \
    RRA:MIN:0.5:288:797 \
    RRA:MAX:0.5:1:600 \
    RRA:MAX:0.5:6:700 \
    RRA:MAX:0.5:24:775 \
    RRA:MAX:0.5:288:797 \
    RRA:LAST:0.5:1:600 \
    RRA:LAST:0.5:6:700 \
    RRA:LAST:0.5:24:775 \
    RRA:LAST:0.5:288:797 \


But a look in the Graph i see this Debug info:


    RRDTool Command:

    /usr/bin/rrdtool graph - \
    --imgformat=PNG \
    --start=-86400 \
    --end=-300 \
    --title="Redheat - EinSensor" \
    --base=1000 \
    --height=120 \
    --width=500 \
    --alt-autoscale-max \
    --lower-limit=-10 \
    --vertical-label="Temperatur" \
    --slope-mode \
    --font TITLE:8:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
    --font AXIS:7:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
    --font LEGEND:7:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
    --font UNIT:7:/usr/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \
    DEF:a="/srv/www/cacti/rra/messpc_data_235.rrd":data:AVERAGE \
    LINE3:a#FF3932:"
Back to top
cpt_ahab
Cacti User


Joined: 01 Feb 2005
Posts: 60

PostPosted: Wed Mar 07, 2007 10:49 am    Post subject: Reply with quote

SNMP Error is ok. I get this one too.

The Datasource looks ok also,
but the graph is different.
SNMP Error is ok. I get this one too.

The Datasource looks ok also,
but the graph is different.
Mine looks like this
Code:
/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Hitzkopf - BGS-Serverraum - Temp" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=-10 \
--vertical-label="Temperatur" \
--slope-mode \
Some lines are missing because the forum cuts my post otherwise


check if your downed host detection is set to ping only.
settings --> poller
if cacti doesnt get some snmp data from the host,
it thinks the host is down and doesnt run the scripts.
Back to top
SimonS



Joined: 15 Mar 2007
Posts: 1

PostPosted: Thu Mar 15, 2007 1:50 pm    Post subject: Re: php script for pcmeasure to run in cacti Reply with quote

Hi Ahab

Code:

<?php
if($argv[1] != '' && $argv[2] != '' && $argv[3] != ''){
   $hip = $argv[1];
   $com = $argv[2];
   $sen = $argv[3];
   $max_sensors = 12;
   if($sen > $max_sensors){
      echo "No Data from sensor ".($sen).". Number of sensors: ".$max_sensors." ";
   }else{
      $data = snmpget($hip, $com, ".1.3.6.1.4.1.14848.2.1.2.1.5.".$sen);
      $data = $data/10;
      echo "data:".$data;
   }
      
}else{
   echo "Usage: <path2php>\php\cli\php.exe <path2script>\messpc.php <ipAdr> <snmpcommunity> <sensor>"."\n";
   echo "Example: E:\php\cli\php.exe E:/inetpub/mrtgroot/cacti/scripts/messpc.php 192.168.13.250 pub 1";
 }
?>


Many thanks for that - one question: isn't snmpget() supposed to have a version in the string, in order to work?

like the commandline :
snmpget 192.168.xxx.xxx -v 1 -c public 1.3.6.1.4.1.14848.2.1.2.1.5.1

which returns correctly:
SNMPv2-SMI::enterprises.14848.2.1.2.1.5.1 = INTEGER: 243

if i run php messpc.php 192.168.xxx.xxx public 1 in a shell, it returns
data:0

any idea if there is the snmp-version missing?

i do have a most recent ethernetbox with 2 temperature sensors (no humid) and a smoke detector.

cacti is 8.6, php 4.4.x on debian sarge 2.6.x

regards
simons
Back to top
Cliff Lang



Joined: 20 Mar 2007
Posts: 1

PostPosted: Tue Mar 20, 2007 8:06 am    Post subject: php script for pcmeasure to run in cacti Reply with quote

The snmpget() in the php script returns everything after the "=" from the commandline snmpget. So when you $data/10; the result is 0 (because it not just the integer). If you remove the $data=$data/10; you will see the result like "INTEGER: 722".
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Scripts and Templates All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group