root / plugins / weather / wfrog @ 17f78427
Historique | Voir | Annoter | Télécharger (2,06 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
|
| 3 |
# Author: William Viker <william.viker@gmail.com> |
| 4 |
# Version: 0.1 |
| 5 |
|
| 6 |
# Non-members may check out a read-only working copy anonymously over HTTP. |
| 7 |
# $ svn checkout http://wfrogmunin.googlecode.com/svn/trunk/ wfrogmunin-read-only |
| 8 |
|
| 9 |
# TODO: |
| 10 |
# * Wait a couple of hours to see if this actually works. |
| 11 |
# * Add proper data labels for the different values possible |
| 12 |
# * more.. |
| 13 |
|
| 14 |
use strict; |
| 15 |
use Data::Dumper; |
| 16 |
|
| 17 |
# INSTRUCTIONS |
| 18 |
# |
| 19 |
# 1. Install wfrog, get it up running with your weather station |
| 20 |
# 2. Locate your wfrog.csv file (wfrog creates after 10 mins) |
| 21 |
# 3. cd /etc/munin/plugins/ |
| 22 |
# 4. ln -s /usr/share/munin/plugins/wfrog wfrog_temp |
| 23 |
# 4. ln -s /usr/share/munin/plugins/wfrog wfrog_pressure |
| 24 |
# 5. etc.. |
| 25 |
# 6. reload munin-node ;-) |
| 26 |
|
| 27 |
|
| 28 |
# In case you need to change this. |
| 29 |
|
| 30 |
my %CONFIG = ( |
| 31 |
'wfrogcsv' => '/var/lib/wfrog/wfrog.csv', |
| 32 |
); |
| 33 |
|
| 34 |
|
| 35 |
my $interesting; |
| 36 |
|
| 37 |
if ($0 =~ m#wfrog_(\w+)#) {
|
| 38 |
$interesting = $1; |
| 39 |
} |
| 40 |
|
| 41 |
else {
|
| 42 |
print STDERR "Symlink the wfrog plugin file to wfrog_something, like wfrog_temperature, etc." . "\n"; |
| 43 |
exit 1; |
| 44 |
} |
| 45 |
|
| 46 |
if (defined $ARGV[0] && $ARGV[0] eq 'autoconf') {
|
| 47 |
print "yes\n"; |
| 48 |
exit 0; |
| 49 |
} |
| 50 |
|
| 51 |
open FILE, "<", $CONFIG{'wfrogcsv'};
|
| 52 |
|
| 53 |
my $header = <FILE>; |
| 54 |
|
| 55 |
seek( FILE, -300, 2 ); |
| 56 |
my @line = readline FILE; |
| 57 |
|
| 58 |
$header =~ s/[\r\n]//gs; # bah @ csv |
| 59 |
$line[-1] =~ s/[\r\n]//gs; # --- " --- |
| 60 |
|
| 61 |
my @Data = split /,/, $line[-1]; |
| 62 |
my @Keys = split /,/, $header; |
| 63 |
|
| 64 |
my $GotKeyName; |
| 65 |
my $GotKeyData; |
| 66 |
my $cpos = 0; |
| 67 |
|
| 68 |
for (@Keys) {
|
| 69 |
if ($_ eq $interesting) {
|
| 70 |
$GotKeyName = $_; |
| 71 |
if (defined $Data[$cpos]) {
|
| 72 |
$GotKeyData = $Data[$cpos]; |
| 73 |
} |
| 74 |
} |
| 75 |
$cpos++; |
| 76 |
} |
| 77 |
|
| 78 |
unless (defined $GotKeyName) {
|
| 79 |
print STDERR "Could not find any data on '$interesting'. Does the file contain any data?\n"; |
| 80 |
exit 1; |
| 81 |
} |
| 82 |
|
| 83 |
my $graph_name = $GotKeyName; |
| 84 |
$graph_name =~ s/[^a-z]//gi; |
| 85 |
|
| 86 |
if (defined $ARGV[0] && $ARGV[0] eq 'config') {
|
| 87 |
print "graph_title WFrog $GotKeyName\n" |
| 88 |
. "graph_args --base 1000 -l 0\n" |
| 89 |
. "graph_vlabel Value\n" |
| 90 |
. "graph_scale yes\n" |
| 91 |
. "graph_category sensors\n" |
| 92 |
# . "graph_printf %3.0lf\n" |
| 93 |
. "$graph_name.label $GotKeyName\n" |
| 94 |
. "$graph_name.draw AREASTACK\n"; |
| 95 |
|
| 96 |
exit 0; |
| 97 |
} |
| 98 |
|
| 99 |
print "$graph_name.value $GotKeyData\n"; |
