Own Script: "CMDPHP: Result from CMD not valid"

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

Moderators: Moderators, Developers

Post Reply
Author
Message
Pinky
Posts: 15
Joined: Sat May 07, 2005 3:00 pm
Location: Germany - Munich

Own Script: "CMDPHP: Result from CMD not valid"

#1 Post by Pinky » Fri Mar 20, 2009 1:09 pm

Hello,
I'am working on a template to graph the results of my digitemp-output.
The logfile I get looks like this:

Code: Select all

sensor 0: 18.937500 degrees C
sensor 1: 22.625000 degrees C
sensor 2: 5.562500 degrees C
sensor 3: 22.125000 degrees C
sensor 4: 63.500000 degrees C
In order to make this logfile useable for cacti I use the following command under "Data Input Methods":

Code: Select all

cat /var/www/tempsensor/temp.txt | awk '{ printf "%s ",$1 $2 $3}'
Testrun:

Code: Select all

server-debian:/usr/share/cacti/site/scripts$ cat /var/www/tempsensor/temp.txt | awk '{ printf "%s ",$1 $2 $3}'
sensor0:18.937500 sensor1:22.625000 sensor2:5.562500 sensor3:22.125000 sensor4:63.500000 server-debian:/usr/share/cacti/site/scripts$
The Problem is, that no graphs are generated, plus I get the following error in my cacti-log:

Code: Select all

03/20/2009 07:00:02 PM - SYSTEM STATS: Time:1.1289 Method:cmd.php Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:13 RRDsProcessed:10
03/20/2009 07:00:01 PM - CMDPHP: Poller[0] Host[0] DS[18] WARNING: Result from CMD not valid. Partial Result: 
DS[18] refers to my digitemp-"Data Source" has the following debug-message:

Code: Select all

/usr/bin/rrdtool create \
/var/lib/cacti/rra/digitemp_18.rrd \
--step 300  \
DS:sensor0:GAUGE:600:0:84 \
DS:sensor1:GAUGE:600:0:100 \
DS:sensor2:GAUGE:600:0:100 \
DS:sensor4:GAUGE:600:0:100 \
DS:sensor3:GAUGE:600:0:100 \
RRA:AVERAGE:0.5:1:500 \
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:MAX:0.5:1:500 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 \
And here is the output of my graph-debug:

Code: Select all

  RRDTool Command:

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="Digitemp" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="°C" \
--slope-mode \
--font TITLE:12: \
--font AXIS:8: \
--font LEGEND:10: \
--font UNIT:8: \
DEF:a="/var/lib/cacti/rra/digitemp_18.rrd":sensor0:MAX \
DEF:b="/var/lib/cacti/rra/digitemp_18.rrd":sensor1:MAX \
DEF:c="/var/lib/cacti/rra/digitemp_18.rrd":sensor2:MAX \
DEF:d="/var/lib/cacti/rra/digitemp_18.rrd":sensor3:MAX \
DEF:e="/var/lib/cacti/rra/digitemp_18.rrd":sensor4:MAX \
 \
 \
 \
 \

RRDTool Says:
Can somebody help me ?

Pinky
Posts: 15
Joined: Sat May 07, 2005 3:00 pm
Location: Germany - Munich

#2 Post by Pinky » Sat Mar 21, 2009 4:29 am

I forgot to post the output of cmd.php (debug-level):

Code: Select all

server-debian:/usr/share/cacti/site$ php -q cmd.php
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[0] DS[18] CMD: /bin/cat /var/www/tempsensor/temp.txt | /usr/bin/awk '{printf "%s ",$1 $2 $3}', output: sensor0:18.625000 sensor1:29.625000 sensor2:2.812500 sensor3:21.875000 sensor4:55.125000
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] PING: Host is alive
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] SNMP: Host responded to SNMP
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[3] CMD: perl /usr/share/cacti/site/scripts/linux_memory.pl MemFree:, output: 39152
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[4] CMD: perl /usr/share/cacti/site/scripts/linux_memory.pl SwapFree:, output: 1305700
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[5] CMD: perl /usr/share/cacti/site/scripts/loadavg_multi.pl, output: 1min:0.09 5min:0.08 10min:0.07
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[6] CMD: perl /usr/share/cacti/site/scripts/unix_users.pl , output: 1
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[7] CMD: perl /usr/share/cacti/site/scripts/unix_processes.pl, output: 133
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[8] CMD: perl /usr/share/cacti/site/scripts/query_unix_partitions.pl  get available /dev/md0, output: 10254608
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[8] CMD: perl /usr/share/cacti/site/scripts/query_unix_partitions.pl  get used /dev/md0, output: 3434068
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[9] CMD: perl /usr/share/cacti/site/scripts/query_unix_partitions.pl  get available /dev/md1, output: 89767620
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[9] CMD: perl /usr/share/cacti/site/scripts/query_unix_partitions.pl  get used /dev/md1, output: 41159968
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[10] CMD: perl /usr/share/cacti/site/scripts/query_unix_partitions.pl  get available /dev/sdb2, output: 0
03/21/2009 10:24:08 AM - CMDPHP: Poller[0] Host[1] DS[10] CMD: perl /usr/share/cacti/site/scripts/query_unix_partitions.pl  get used /dev/sdb2, output: 83534648
03/21/2009 10:24:09 AM - CMDPHP: Poller[0] Host[2] PING: UDP ping Timed out
03/21/2009 10:24:09 AM - CMDPHP: Poller[0] Time: 0.5308 s, Theads: N/A, Hosts: 2
server-debian:/usr/share/cacti/site$

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#3 Post by gandalf » Sun Mar 22, 2009 4:43 am

Now I'm stuck. The first post says "Result not valid" but the second post shows the results?
To be honest, I did not know that cacti will accept a full shell command in this way, but the second post shows that it's working. Please see 2nd link of my sig for more hints
Reinhard

Pinky
Posts: 15
Joined: Sat May 07, 2005 3:00 pm
Location: Germany - Munich

#4 Post by Pinky » Tue Mar 24, 2009 4:35 pm

I experimented for a while, it seems like, that now some data is added to the rra, but still no graph can be seen

Code: Select all

03/24/2009 10:41:31 PM - CMDPHP: Poller[0] Host[1] DS[24] CMD: /bin/cat /var/www/tempsensor/temp.txt | /usr/bin/awk '{printf "%s ",$1 $2 $3}', output: sensor0:18.375000 sensor1:23.187500 sensor2:4.875000 sensor3:24.187500 sensor4:64.437500
03/24/2009 10:41:31 PM - CMDPHP: Poller[0] Host[1] DS[25] CMD: /usr/share/cacti/site/scripts/digitemp_single.sh 0, output: 18.375000

Code: Select all

03/24/2009 10:41:33 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/lib/cacti/rra/localhost_sensor1_24.rrd --template sensor0:sensor1:sensor2:sensor3:sensor4 1237930892:18.375000:23.187500:4.875000:24.187500:64.437500
OK u:0.00 s:0.01 r:1.01
03/24/2009 10:41:33 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /var/lib/cacti/rra/localhost_temperature_25.rrd --template temperature 1237930892:18.375000
OK u:0.00 s:0.01 r:1.01

Last edited by Pinky on Tue Mar 24, 2009 4:50 pm, edited 2 times in total.

User avatar
BSOD2600
Cacti Moderator
Posts: 12160
Joined: Sat May 08, 2004 12:44 pm
Location: USA

#5 Post by BSOD2600 » Tue Mar 24, 2009 4:46 pm

What happened to sensor1 output?

rrdtool fetch AVERAGE localhost_sensor1_24.rrd show the correct data you've been retrieving?

At least for Windows boxes, when rrdtool graph doesn't show any error, it's due to a permission problem. Do other standard graphs work fine?

Pinky
Posts: 15
Joined: Sat May 07, 2005 3:00 pm
Location: Germany - Munich

#6 Post by Pinky » Tue Mar 24, 2009 4:47 pm

sorry, but there was an error in my Data Template. I edited my post.
Still no temperature-graphs... other graphs work fine

Pinky
Posts: 15
Joined: Sat May 07, 2005 3:00 pm
Location: Germany - Munich

#7 Post by Pinky » Tue Mar 24, 2009 4:50 pm

here is the output of rrdtool fetch:

Code: Select all

rrdtool fetch AVERAGE /var/lib/cacti/rra/localhost_sensor1_24.rrd
ERROR: unknown consolidation function '/var/lib/cacti/rra/localhost_temperature_25.rrd'
rrdtool info; last_ds shows reasonable content :

Code: Select all

server-debian:/var/lib/cacti/rra$ rrdtool info localhost_sensor1_24.rrd
filename = "localhost_sensor1_24.rrd"
rrd_version = "0003"
step = 300
last_update = 1237931360
ds[sensor0].type = "GAUGE"
ds[sensor0].minimal_heartbeat = 600
ds[sensor0].min = 0,0000000000e+00
ds[sensor0].max = 1,0000000000e+02
ds[sensor0].last_ds = "18.375000"
ds[sensor0].value = 4,7775000000e+03
ds[sensor0].unknown_sec = 0
ds[sensor1].type = "GAUGE"
ds[sensor1].minimal_heartbeat = 600
ds[sensor1].min = 0,0000000000e+00
ds[sensor1].max = 1,0000000000e+02
ds[sensor1].last_ds = "23.062500"
ds[sensor1].value = 5,9962500000e+03
ds[sensor1].unknown_sec = 0
ds[sensor2].type = "GAUGE"
ds[sensor2].minimal_heartbeat = 600
ds[sensor2].min = 0,0000000000e+00
ds[sensor2].max = 1,0000000000e+02
ds[sensor2].last_ds = "4.812500"
ds[sensor2].value = 1,2512500000e+03
ds[sensor2].unknown_sec = 0
ds[sensor4].type = "GAUGE"
ds[sensor4].minimal_heartbeat = 600
ds[sensor4].min = 0,0000000000e+00
ds[sensor4].max = 1,0000000000e+02
ds[sensor4].last_ds = "64.000000"
ds[sensor4].value = 1,6640000000e+04
ds[sensor4].unknown_sec = 0
ds[sensor3].type = "GAUGE"
ds[sensor3].minimal_heartbeat = 600
ds[sensor3].min = 0,0000000000e+00
ds[sensor3].max = 1,0000000000e+02
ds[sensor3].last_ds = "24.187500"
ds[sensor3].value = 6,2887500000e+03
ds[sensor3].unknown_sec = 0
rra[0].cf = "AVERAGE"
rra[0].rows = 500
rra[0].cur_row = 458
rra[0].pdp_per_row = 1
rra[0].xff = 5,0000000000e-01
rra[0].cdp_prep[0].value = NaN
rra[0].cdp_prep[0].unknown_datapoints = 0
rra[0].cdp_prep[1].value = NaN
rra[0].cdp_prep[1].unknown_datapoints = 0
rra[0].cdp_prep[2].value = NaN
rra[0].cdp_prep[2].unknown_datapoints = 0
rra[0].cdp_prep[3].value = NaN
rra[0].cdp_prep[3].unknown_datapoints = 0
rra[0].cdp_prep[4].value = NaN
rra[0].cdp_prep[4].unknown_datapoints = 0
rra[1].cf = "AVERAGE"
rra[1].rows = 600
rra[1].cur_row = 313
rra[1].pdp_per_row = 1
rra[1].xff = 5,0000000000e-01
rra[1].cdp_prep[0].value = NaN
rra[1].cdp_prep[0].unknown_datapoints = 0
rra[1].cdp_prep[1].value = NaN
rra[1].cdp_prep[1].unknown_datapoints = 0
rra[1].cdp_prep[2].value = NaN
rra[1].cdp_prep[2].unknown_datapoints = 0
rra[1].cdp_prep[3].value = NaN
rra[1].cdp_prep[3].unknown_datapoints = 0
rra[1].cdp_prep[4].value = NaN
rra[1].cdp_prep[4].unknown_datapoints = 0
rra[2].cf = "AVERAGE"
rra[2].rows = 700
rra[2].cur_row = 368
rra[2].pdp_per_row = 6
rra[2].xff = 5,0000000000e-01
rra[2].cdp_prep[0].value = 3,6757916667e+01
rra[2].cdp_prep[0].unknown_datapoints = 1
rra[2].cdp_prep[1].value = 4,6288333333e+01
rra[2].cdp_prep[1].unknown_datapoints = 1
rra[2].cdp_prep[2].value = 9,7225000000e+00
rra[2].cdp_prep[2].unknown_datapoints = 1
rra[2].cdp_prep[3].value = 1,2881547619e+02
rra[2].cdp_prep[3].unknown_datapoints = 1
rra[2].cdp_prep[4].value = 4,8367083333e+01
rra[2].cdp_prep[4].unknown_datapoints = 1
rra[3].cf = "AVERAGE"
rra[3].rows = 775
rra[3].cur_row = 126
rra[3].pdp_per_row = 24
rra[3].xff = 5,0000000000e-01
rra[3].cdp_prep[0].value = 3,6757916667e+01
rra[3].cdp_prep[0].unknown_datapoints = 19
rra[3].cdp_prep[1].value = 4,6288333333e+01
rra[3].cdp_prep[1].unknown_datapoints = 19
rra[3].cdp_prep[2].value = 9,7225000000e+00
rra[3].cdp_prep[2].unknown_datapoints = 19
rra[3].cdp_prep[3].value = 1,2881547619e+02
rra[3].cdp_prep[3].unknown_datapoints = 19
rra[3].cdp_prep[4].value = 4,8367083333e+01
rra[3].cdp_prep[4].unknown_datapoints = 19
rra[4].cf = "AVERAGE"
rra[4].rows = 797
rra[4].cur_row = 616
rra[4].pdp_per_row = 288
rra[4].xff = 5,0000000000e-01
rra[4].cdp_prep[0].value = 3,6757916667e+01
rra[4].cdp_prep[0].unknown_datapoints = 259
rra[4].cdp_prep[1].value = 4,6288333333e+01
rra[4].cdp_prep[1].unknown_datapoints = 259
rra[4].cdp_prep[2].value = 9,7225000000e+00
rra[4].cdp_prep[2].unknown_datapoints = 259
rra[4].cdp_prep[3].value = 1,2881547619e+02
rra[4].cdp_prep[3].unknown_datapoints = 259
rra[4].cdp_prep[4].value = 4,8367083333e+01
rra[4].cdp_prep[4].unknown_datapoints = 259
rra[5].cf = "MAX"
rra[5].rows = 500
rra[5].cur_row = 374
rra[5].pdp_per_row = 1
rra[5].xff = 5,0000000000e-01
rra[5].cdp_prep[0].value = NaN
rra[5].cdp_prep[0].unknown_datapoints = 0
rra[5].cdp_prep[1].value = NaN
rra[5].cdp_prep[1].unknown_datapoints = 0
rra[5].cdp_prep[2].value = NaN
rra[5].cdp_prep[2].unknown_datapoints = 0
rra[5].cdp_prep[3].value = NaN
rra[5].cdp_prep[3].unknown_datapoints = 0
rra[5].cdp_prep[4].value = NaN
rra[5].cdp_prep[4].unknown_datapoints = 0
rra[6].cf = "MAX"
rra[6].rows = 600
rra[6].cur_row = 244
rra[6].pdp_per_row = 1
rra[6].xff = 5,0000000000e-01
rra[6].cdp_prep[0].value = NaN
rra[6].cdp_prep[0].unknown_datapoints = 0
rra[6].cdp_prep[1].value = NaN
rra[6].cdp_prep[1].unknown_datapoints = 0
rra[6].cdp_prep[2].value = NaN
rra[6].cdp_prep[2].unknown_datapoints = 0
rra[6].cdp_prep[3].value = NaN
rra[6].cdp_prep[3].unknown_datapoints = 0
rra[6].cdp_prep[4].value = NaN
rra[6].cdp_prep[4].unknown_datapoints = 0
rra[7].cf = "MAX"
rra[7].rows = 700
rra[7].cur_row = 199
rra[7].pdp_per_row = 6
rra[7].xff = 5,0000000000e-01
rra[7].cdp_prep[0].value = 1,8382916667e+01
rra[7].cdp_prep[0].unknown_datapoints = 1
rra[7].cdp_prep[1].value = 2,3187500000e+01
rra[7].cdp_prep[1].unknown_datapoints = 1
rra[7].cdp_prep[2].value = 4,8908333333e+00
rra[7].cdp_prep[2].unknown_datapoints = 1
rra[7].cdp_prep[3].value = 6,4687500000e+01
rra[7].cdp_prep[3].unknown_datapoints = 1
rra[7].cdp_prep[4].value = 2,4187500000e+01
rra[7].cdp_prep[4].unknown_datapoints = 1
rra[8].cf = "MAX"
rra[8].rows = 775
rra[8].cur_row = 673
rra[8].pdp_per_row = 24
rra[8].xff = 5,0000000000e-01
rra[8].cdp_prep[0].value = 1,8382916667e+01
rra[8].cdp_prep[0].unknown_datapoints = 19
rra[8].cdp_prep[1].value = 2,3187500000e+01
rra[8].cdp_prep[1].unknown_datapoints = 19
rra[8].cdp_prep[2].value = 4,8908333333e+00
rra[8].cdp_prep[2].unknown_datapoints = 19
rra[8].cdp_prep[3].value = 6,4687500000e+01
rra[8].cdp_prep[3].unknown_datapoints = 19
rra[8].cdp_prep[4].value = 2,4187500000e+01
rra[8].cdp_prep[4].unknown_datapoints = 19
rra[9].cf = "MAX"
rra[9].rows = 797
rra[9].cur_row = 418
rra[9].pdp_per_row = 288
rra[9].xff = 5,0000000000e-01
rra[9].cdp_prep[0].value = 1,8382916667e+01
rra[9].cdp_prep[0].unknown_datapoints = 259
rra[9].cdp_prep[1].value = 2,3187500000e+01
rra[9].cdp_prep[1].unknown_datapoints = 259
rra[9].cdp_prep[2].value = 4,8908333333e+00
rra[9].cdp_prep[2].unknown_datapoints = 259
rra[9].cdp_prep[3].value = 6,4687500000e+01
rra[9].cdp_prep[3].unknown_datapoints = 259
rra[9].cdp_prep[4].value = 2,4187500000e+01
rra[9].cdp_prep[4].unknown_datapoints = 259
server-debian:/var/lib/cacti/rra$

Pinky
Posts: 15
Joined: Sat May 07, 2005 3:00 pm
Location: Germany - Munich

#8 Post by Pinky » Wed Mar 25, 2009 4:41 pm

Is it a problem for cacti, if the script adds a newline to it's output ?
For example:

Code: Select all

#!/bin/sh
cat /var/www/tempsensor/temp.txt | grep "sensor $1" | awk '{print $3}'

Code: Select all

server-debian:/usr/share/cacti/site/scripts$ ./digitemp_single.sh 0
17.812500
server-debian:/usr/share/cacti/site/scripts$
unix_user doesn't do this.

Code: Select all

server-debian:/usr/share/cacti/site/scripts$ perl unix_users.pl
1server-debian:/usr/share/cacti/site/scripts$
I am really lost on this :)

User avatar
BSOD2600
Cacti Moderator
Posts: 12160
Joined: Sat May 08, 2004 12:44 pm
Location: USA

#9 Post by BSOD2600 » Wed Mar 25, 2009 5:35 pm

Pinky wrote:Is it a problem for cacti, if the script adds a newline to it's output ?
Yes. The formatted output should be on one line.

One of your debug outputs, before you editied it, I saw cacti with the multiline parsing stuff for each sensor field -- that is a good thing, since cacti is recognizing the various fields of the script and mapping them to the Data Input Method fields (which should map to the Data Template fields).

Pinky
Posts: 15
Joined: Sat May 07, 2005 3:00 pm
Location: Germany - Munich

#10 Post by Pinky » Sat Mar 28, 2009 9:56 am

Ok, my graphs are working now. Unfortunately I there were some bugs in my Graph Template.

But I've one more question:
Sometimes the sensor fails and returns 85.00°C. Is it possible to skip every 85.00°C dataset, and still draw a contiuous line ? The graphs I've right now ,have to unpleasant breakaways.

User avatar
BSOD2600
Cacti Moderator
Posts: 12160
Joined: Sat May 08, 2004 12:44 pm
Location: USA

#11 Post by BSOD2600 » Sun Mar 29, 2009 12:50 am

If you set an appropriate Data Source MAX in the data template, it'll ignore values outside the min/max range. Of course, your existing rrd files won't take the change automatically, so you either have to manually update it (rrdtool tune) or delete it so cacti re-creates it.

titus
Cacti User
Posts: 72
Joined: Thu Oct 02, 2008 10:54 am

#12 Post by titus » Thu Apr 29, 2010 10:31 am

Hello Im using http://sonium.blogspot.com/2006/09/cact ... iends.html script for logging temperature.

but graph shows zero values :(.
When I mannualy run php -q cmd.php I see this in cacti log

Code: Select all

04/29/2010 05:27:08 PM - CMDPHP: Poller[0] Host[2] DS[34] CMD: python /var/www/cacti/scripts/digitemp.py soba, output: soba:24.94
everything sems ok. Should output be just a number ?

But when cacti runs it by itself then instead of output I get "U", i ran script both as a cacti user and a root user.

data input method is Script/Command
path is

Code: Select all

python /var/www/cacti/scripts/digitemp.py soba
output field is set to update RRD file. graph template is ok.

Only thing about output fields is

Code: Select all

Field [Output]
and

Code: Select all

Friendly Name
are those values connected with other steps for creating graphs? I typed everywhere same names.[/code]

Post Reply