php script for pcmeasure to run in cacti

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

Moderators: Moderators, Developers

Post Reply
Author
Message
User avatar
cpt_ahab
Cacti User
Posts: 60
Joined: Tue Feb 01, 2005 11:34 am

php script for pcmeasure to run in cacti

#1 Post by cpt_ahab » Tue Apr 19, 2005 3:45 am

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

Code: Select all

<?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.

mhinti
Posts: 27
Joined: Thu Jun 30, 2005 9:23 am
Location: Austria

#2 Post by mhinti » Thu Jun 30, 2005 9:25 am

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

User avatar
cpt_ahab
Cacti User
Posts: 60
Joined: Tue Feb 01, 2005 11:34 am

#3 Post by cpt_ahab » Tue Jul 12, 2005 9:17 am

Here is is... :D

GreeZ ahab
Attachments
pcmeasure_tmpl.txt
In this Textfile is the xml-code for the cacti graphtemplate of the pc measure-box. Both Humidity and Temperature
(17.23 KiB) Downloaded 3926 times

lord0815
Posts: 8
Joined: Wed Apr 27, 2005 3:08 am

#4 Post by lord0815 » Wed Feb 21, 2007 5:44 am

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

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

Code: Select all

 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: Select all

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: Select all

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: Select all

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: Select all

php /srv/www/cacti/scripts/messpc1.php 172.16.1.1 public 1
print the following output

Code: Select all

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!

User avatar
cpt_ahab
Cacti User
Posts: 60
Joined: Tue Feb 01, 2005 11:34 am

#5 Post by cpt_ahab » Tue Feb 27, 2007 3:47 am

Hello

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

You should see a line like

Code: Select all

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: Select all

whereis php
cacti 0.8.6j ** cactid 0.8.6d ** rrdtool 1.2.15
Debain ** Apache 2 ** PHP 4.3.0

lord0815
Posts: 8
Joined: Wed Apr 27, 2005 3:08 am

#6 Post by lord0815 » Mon Mar 05, 2007 8:38 am

Hey!

Okay, i

lord0815
Posts: 8
Joined: Wed Apr 27, 2005 3:08 am

#7 Post by lord0815 » Mon Mar 05, 2007 8:39 am

Hey!

Okay, i

lord0815
Posts: 8
Joined: Wed Apr 27, 2005 3:08 am

#8 Post by lord0815 » Mon Mar 05, 2007 8:40 am

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:"

User avatar
cpt_ahab
Cacti User
Posts: 60
Joined: Tue Feb 01, 2005 11:34 am

#9 Post by cpt_ahab » Wed Mar 07, 2007 10:49 am

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: Select all

/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.
cacti 0.8.6j ** cactid 0.8.6d ** rrdtool 1.2.15
Debain ** Apache 2 ** PHP 4.3.0

SimonS
Posts: 1
Joined: Thu Mar 15, 2007 1:37 pm

Re: php script for pcmeasure to run in cacti

#10 Post by SimonS » Thu Mar 15, 2007 1:50 pm

Hi Ahab

Code: Select all

<?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

Cliff Lang
Posts: 1
Joined: Tue Mar 20, 2007 6:26 am

php script for pcmeasure to run in cacti

#11 Post by Cliff Lang » Tue Mar 20, 2007 8:06 am

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".

Schparc
Posts: 3
Joined: Thu Oct 21, 2010 3:08 am
Location: Germany Rösrath
Contact:

Re: php script for pcmeasure to run in cacti

#12 Post by Schparc » Wed Nov 17, 2010 1:54 am

Schönen guten Tag,

ich bräuchte auch einem Hilfe ! Ich habe die Templates für die Temperatur in eine eigene XML gepackt und hinzugefügt.

Dann habe ich unter DATA Sources einen Graf erstellt it diesem Redhead. mehr noch nicht.

Dann muss man ja die 3 Punkte

Index des Sensors
Snmp Community von Redheat
IP-Adresse von REDHEAT

ausfüllen. Nur wal muss ich als Index eintragen wenn ich den Port 1 ( Temperatur des Raumes) habe?

Bitte ich brauche das dringend.

Hier aus dem Log der Fehler

Code: Select all

11/17/2010 07:57:57 AM - CMDPHP: Poller[0] WARNING: SNMP Get Timeout for Host:'35.101.11.150', and OID:'.1.3.6.1.2.1.1.1.0' 

Schparc
Posts: 3
Joined: Thu Oct 21, 2010 3:08 am
Location: Germany Rösrath
Contact:

Re: php script for pcmeasure to run in cacti

#13 Post by Schparc » Fri Nov 19, 2010 3:29 am

Ok fehler behoben. !!! die PHP datei muss angepasst werden. WErde den Quelltext mal Posten wenn Ihn einer braucht.

Ok I found the false !!! You must change something in the PHP File. I Could Post it when Somebody need this.

Sorry for my bad English :)

Schparc

mischu
Posts: 1
Joined: Fri Mar 09, 2012 11:33 am

Re: php script for pcmeasure to run in cacti

#14 Post by mischu » Fri Mar 09, 2012 11:40 am

Does anyone maybe have a nice step by step PDF like "how to add pcmeasure in cacti"

i've imported the templates but i dont know how to handle it...
i recieve nice responses when i test it with the snmpwalk.


PS: im running linux (redhat with cacti 0.8.7h)

thanks

noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: php script for pcmeasure to run in cacti

#15 Post by noname » Mon Mar 26, 2012 2:07 am

mischu wrote:Does anyone maybe have a nice step by step PDF like "how to add pcmeasure in cacti"

i've imported the templates but i dont know how to handle it...
i recieve nice responses when i test it with the snmpwalk.


PS: im running linux (redhat with cacti 0.8.7h)

thanks
1) Import the template
2) Place the script (messpc1.php) at scripts/ directory
3) In 'Data Input Methods -> Redheat - EinSensor', change the script path from "E:\\php\\cli\\php.exe" to "php"

Post Reply