#!/usr/bin/perl -w # # Anime recording system foltia # http://www.dcc-jpl.com/soft/foltia/ # # munin用温度監視モジュール/Linux / lm_sensors # # DCC-JPL Japan/foltia project # # # How to install to munin. # munin : http://munin.projects.linpro.no/ # # su - # cp temperature.pl /usr/share/munin/plugins/temperature # ln -s /usr/share/munin/plugins/temperature /etc/munin/plugins/ # restart munin-node Ex. service munin-node reload # # use strict; use warnings; if ($#ARGV > -1 ){ if ( $ARGV[0] eq "autoconf" ){ my $lmsensorspath = `which sensors`; if ($lmsensorspath eq ""){ print "no\n"; }else{ print "yes\n"; } exit 0; }elsif($ARGV[0] eq "config"){ print "graph_title Universal temperatures. \n"; print "graph_args --base 1000 -l 0\n"; print "graph_vlabel Celsius\n"; print "graph_scale no\n"; print "graph_category sensors\n"; print "graph_info This graph shows the temperature in degrees Celsius of lm_sensors in the machine and AMEDAS.\n"; &extracttempratures("config"); print "amedas.label amedas\n"; #print "amedas.type DERIVE\n"; print "amedas.info temperature from amedas\n"; exit; }else{ &extracttempratures(); my $amedasvalue = &getamedastemp(); print "amedas.value $amedasvalue\n"; exit; } }else{ &extracttempratures(); my $amedasvalue = &getamedastemp(); print "amedas.value $amedasvalue\n"; exit; } sub extracttempratures(){ #print "$#_\n\n"; my $flag = ""; if ($#_ == 0){ if ($_[0] eq "config"){ $flag = "config"; } }else{ $flag = "value"; }#endif value #my $sensors=`cat ./mer-sensors.txt`; my $sensors = `which sensors`; $sensors = `$sensors`; my @sensor = split(/\n/, $sensors); my $data = ""; my $counter = "0"; my @tmp1 = ""; my $temperature = ""; foreach $data (@sensor){ if ($data =~ /[0-9].*C/){ @tmp1 =split(/\(/, $data); @tmp1 =split(/:/, $tmp1[0]); $temperature = $tmp1[1]; $temperature =~ s/[^0-9.-]//gi; if ($flag eq "config"){ print "$tmp1[0]_$counter.label $tmp1[0]_$counter\n"; #print "$tmp1[0]_$counter.type DERIVE\n"; print "$tmp1[0]_$counter.info temperature on $tmp1[0]_$counter\n"; #print "$tmp1[0]_$counter.max 200\n"; #print "$tmp1[0]_$counter.min -20\n"; }else{ print "$tmp1[0]_$counter.value $temperature\n"; } $counter++; }#if }#foreach }#endsub sub getamedastemp(){ use LWP::Simple; my $rssurl = ""; if ($#_ > -1 ){ $rssurl = $_[0] ; }else{ #Config section #デフォルトで八王子 $rssurl = "http://weather.livedoor.com/forecast/rss/amedas/point/44112.xml"; } my ($content) = get("$rssurl"); my (@line) = split(/\n/, $content); foreach(@line){ if( /の気温/){ my (@linetmp) = ""; @linetmp = split(/]/, $_); @linetmp = split(/