TARGET !scriptname

Support questions about the Network Weather Map plugin

Moderators: Developers, Moderators

Post Reply
Nicktrk
Posts: 5
Joined: Tue Feb 17, 2015 9:01 pm

TARGET !scriptname

Post by Nicktrk »

Hello

Can Weather map display the value of a script other then a numeric value like text?

I have a script that produces the current running artist/song on my MPD server and thought it would be cool to display on my weather map.

I tried a few things with TARGET !/cacti/scripts/getsong.sh but I believe its looking for a numeric value.


Thanks
Nick
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Re: TARGET !scriptname

Post by Howie »

From the manual: http://network-weathermap.com/manual/0. ... tml#script

It looks to me as if you can have your script output:

Code: Select all

0
0
Artist
Title
and then use {node:blah:external_line3} and {node:blah:external_line4} to use them. I haven't actually tested that particular plugin in a very long time, though!
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
Nicktrk
Posts: 5
Joined: Tue Feb 17, 2015 9:01 pm

Re: TARGET !scriptname

Post by Nicktrk »

Very cool Howie it works!

I have one strange problem though. There's a character on my map looks like a backtick but not sure what it is. I turned on debug but nothing shows up in the logs.

Any idea where that character is coming from at the end of the song title? I tried various things in my script that are commented out but they all show that character.
If I have the script produce no output that character still shows up.

My conf

NODE node01535
LABEL {node:this:external_line4}
LABELOUTLINECOLOR none
LABELBGCOLOR none
LABELFONTCOLOR 255 255 255
TARGET !/var/lib/cacti/scripts/getsong.sh
USESCALE none in percent
POSITION 425 210

My script

#!/bin/sh
#artist="`mpc -h 192.168.5.10 current -f %artist%`"
#song="`mpc -h 192.168.5.10 current `"
#title="'mpc -h 192.168.5.10 current -f %title'"
title="`mpc -h 192.168.5.10 --format \"[[%artist% - ]%title%]\" | head -n 1`"
echo 1
echo 2
echo 3
echo $title


Thanks,

Nick
Attachments
screenshot-area-2015-02-18-141654.png
screenshot-area-2015-02-18-141654.png (4.51 KiB) Viewed 3175 times
Robsan
Posts: 2
Joined: Thu May 28, 2015 9:19 pm

Re: TARGET !scriptname

Post by Robsan »

Hello Howie,

I am having the same issue with the backtick being displayed at the end of the string. Looks like there's a return being added too, please see the attached image. I'm using version 0.97c. Is there a solution to fix this?

Cheers,

Rob

Code: Select all

#!/bin/bash
echo 1
echo 2
echo test
echo extern-test

Code: Select all

NODE dd-wrt-front
LABEL {node:this:external_line4}
INFOURL /device/device=11/
NOTES dd-wrt-front
OVERLIBGRAPH /graph.php?height=100&width=512&device=11&type=device_bits&legend=no
ICON images/wireless_1_sm.png
TARGET !/opt/observium/html/weathermap/devicestates/test.sh
LABELOFFSET 0 62
POSITION 928 500
Attachments
extern_test.png
extern_test.png (27.62 KiB) Viewed 2883 times
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Re: TARGET !scriptname

Post by Howie »

Could you run with DEBUG, and check the logs, just to see what weathermap thinks is happening? Look for the ReadData lines.
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
Robsan
Posts: 2
Joined: Thu May 28, 2015 9:19 pm

Re: TARGET !scriptname

Post by Robsan »

Howie,

Here are the wm_debug ReadData outputs:

ExternalScript ReadData: Returning (1,2,1432958162)
ExternalScript ReadData: Running ../../html/weathermap/devicestates/test.sh

I took a look at the WeatherMapDataSource_external.php script and dumped the arrays to a text file. I wanted to see how the PHP code was interpreting the test.sh shell script. The arrays, $lines and $data, look correct and don't contain a backtick.

Debug code I added to WeatherMapDataSource_external.php:

Code: Select all

                ob_start();
                var_dump($lines);
                $linesDump=ob_get_contents();
                ob_end_clean();
                ob_start();
                var_dump($data);
                $dataDump=ob_get_contents();
                ob_end_clean();
                $externFile = "./WeatherMapDataSource_external_lines.txt";
                $fh = fopen($externFile, 'w') or die("fopen can not write to file");
                fwrite($fh, $command . "\r\n");
                fwrite($fh, $linesDump);
                fwrite($fh, $dataDump);
                fclose($fh);
Ouput of added code:

Code: Select all

array(5) {
  [0]=>
  string(2) "1
"
  [1]=>
  string(2) "2
"
  [2]=>
  string(5) "test
"
  [3]=>
  string(12) "extern-test
"
  [4]=>
  bool(false)
}
array(2) {
  [0]=>
  float(1)
  [1]=>
  float(2)
}
Thoughts of what could be the problem?

Rob
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Re: TARGET !scriptname

Post by Howie »

fgets() gets lines, but leaves the whitespace on them.

Code: Select all

                                        $lines[$i++] = fgets($pipe,1024);
should become

Code: Select all

                                        $lines[$i++] = rtrim(fgets($pipe,1024));
I guess some recent change in gd has made it so \n actually renders, because it was tested OK back when it was written!
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
Nicktrk
Posts: 5
Joined: Tue Feb 17, 2015 9:01 pm

Re: TARGET !scriptname

Post by Nicktrk »

Nice work Howie. I can think of a hundred uses for it.
screenshot-area-2015-06-23-152408.png
screenshot-area-2015-06-23-152408.png (60.52 KiB) Viewed 2666 times
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Re: TARGET !scriptname

Post by Howie »

Nice :-)
Weathermap 0.98a is out! & QuickTree 1.0. Superlinks is over there now (and built-in to Cacti 1.x).
Some Other Cacti tweaks, including strip-graphs, icons and snmp/netflow stuff.
(Let me know if you have UK DevOps or Network Ops opportunities, too!)
bartc
Posts: 17
Joined: Wed Aug 20, 2014 11:06 am

Re: TARGET !scriptname

Post by bartc »

THIS IS AWESOME! :)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests