Start arrow Linux Tipps arrow Howtos arrow Howto: UPS with (Gentoo) Linux using NUT with MRTG Statistics
     
 
Hauptmenü
Start
Neuigkeiten
Bildergalerie
Linux Tipps
Modellflug
Segelfliegen
Über mich
Kontakt
Suchen
Wer ist online
 
Howto: UPS with (Gentoo) Linux using NUT with MRTG Statistics PDF
Geschrieben von Administrator   
Freitag, 9. Februar 2007

Howto: UPS with (Gentoo) Linux using NUT with MRTG Statistics


1.) Introduction  
 
I use the Mustek Powermust USB 2000VA UPS  
 
This UPS is supported by nut version >= 2.0.1  
 
Important Notice:  
I recommend you to use the "powermust" driver, as the "mustek" driver doesn't support 24V
UPSes and then you get as battery.value always 100% charge.
Besides, the "powermust" driver has more features.
 
 
 
2.) Install necessary packages  
 

emerge nut apache2 mrtg  
 
Add apache to your default runlevel if you don't have done it yet:  
 
rc-update add apache2 default  
 
Notice: If you also have a Mustek UPS it might be necessary to use the ~x86 version of nut
because at the moment the latest stable version of nut in the portage tree is version 2.0.0-r1
and this version of nut doesn't support the Mustek UPS series.
So you might do  
 
echo "www-apps/nut ~x86" >> /etc/portage/package.keywords  
 
before merging nut!  
 
If you don't have installed a cron daemon install one, e.g.: emerge vixie-cron  
 
 
 
3.) Configure nut  
 
Notice: The following configuration files are adapted for a Mustek UPS, if you use another
UPS you will need to change this files for your UPS!
My UPS is connected to COM1 (/dev/ttyS0).  
 
The configuration files of nut are located under /etc/nut!  
 
Index of ups.conf:  
 
[server]
       driver = powermust
       port = /dev/ttyS0
 
 
Index of upsd.conf:  
 
ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32
ACCEPT localhost
REJECT all
 
 
Index of upsd.users:  
 
       [admin]
              password = yoursecretpassword
              actions = SET
              instcmds = ALL
 
 
       [monuser]
              password = yoursecretpassword
              allowfrom = localhost markus
 
 
Index of upsmon.conf:  
 

RUN_AS_USER root
MONITOR server@localhost 1 monuser yoursecretpassword master
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5
 
 
 
Index of upssched.conf:  
 
CMDSCRIPT /usr/local/ups/bin/upssched-cmd  
 
 
Start the daemons an add them to the default runlevel:  
 
/etc/init.d/upsd start
/etc.init.d/upsmon start
rc-update add upsd default
rc-update add upsmon default
 
 
 
Test if you are able to check the status of your UPS:
 
 
upsc server@localhost  
 
 
You should get a output like this:  

battery.charge: 75.0
battery.voltage: 25.4
battery.voltage.nominal: 24.0
driver.name: powermust
driver.parameter.port: /dev/ttyS0
driver.version: 2.0.2
driver.version.internal: 1.1
input.voltage: 228.6
input.voltage.fault: 228.1
input.voltage.maximum: 234.4
input.voltage.minimum: 227.6
output.frequency: 50.1
output.voltage: 225.7
output.voltage.target.battery: 220.0
ups.delay.shutdown: 2
ups.delay.start: 3
ups.load: 9.0
ups.mfr: Mustek
ups.model: PowerMust
ups.serial: unknown
ups.status: OL
 
 
Notice: If your ouput is different you might have to need change your mrtg config files - see next chapter!  
 
 
4.) Configure MRTG  
 
 
Create the directory /etc/mrtg/ups/:  
 
mkdirhier /etc/mrtg/ups/  
 
Download this tar archive and extract it in this directory:  
 
cd /etc/mrtg/ups/
tar xvf index.tar
 
 
Make all *.sh-files executable: chmod 755 *.sh  
 
You might have to adapt this files for your system!  
 
 
Create the index.html file:  

/usr/bin/indexmaker \
--output=/var/www/localhost/htdocs/ups/index.html \
--title="USV Status" --sort=name --enumerate \
/etc/mrtg/ups/voltage.cfg \
/etc/mrtg/ups/batteryvoltage.cfg \
/etc/mrtg/ups/batterycharge.cfg \
/etc/mrtg/ups/load.cfg \
/etc/mrtg/ups/frequency.cfg \
/etc/mrtg/ups/status.cfg \
 
 
 
Create the directory /etc/cron.mrtg an create a file named ups.sh with this content...  
 
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/ups/voltage.cfg
/usr/bin/mrtg /etc/mrtg/ups/batteryvoltage.cfg
/usr/bin/mrtg /etc/mrtg/ups/batterycharge.cfg
/usr/bin/mrtg /etc/mrtg/ups/status.cfg
/usr/bin/mrtg /etc/mrtg/ups/load.cfg
/usr/bin/mrtg /etc/mrtg/ups/frequency.cfg
 
 
... and make it executable: chmod 755 ups.sh  
 
Execute this script (/etc/cron.mrtg/ups.sh) at least three times (don't care about the warnings)!  
 
Run the command crontab -e and add this line to update the statistics every 5 minutes:  
 
*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null  
 
 
5.) Testing  
 
Now open your web browser and open the page http://yourserver/ups  
 
Your should now see your statistics, here a picture of mine:  
 
 
 
 
 
6.) Sending an email when UPS is offline (Optitional)  
 
 
 
I use ssmtp to send my an email via my yahoo account to an another email-address of an ISP
which allows forwarding emails to sms, so I get a sms to my mobile phone when the UPS is offine.  
 
Configure ssmtp (/etc/ssmtp/ssmtp.conf):  
 

root= Diese E-Mail-Adresse ist gegen Spam-Bots geschützt, du musst Javascript aktivieren, damit du sie sehen kannst
mailhub=smtp.mail.yahoo.com
rewriteDomain=yahoo.de
FromLineOverride=YES  
 
Create a file named upsmail.sh in your home directory (root) with this content...  
 

if [ "`upsc server@localhost ups.status|grep OL`" == "" ]
then
echo "Subject: USV OFFLINE" > /tmp/usv.msg
echo "" >> /tmp/usv.msg
upsc server@localhost |grep "battery.charge" >> /tmp/usv.msg
upsc server@localhost |grep "battery.voltage:" >> /tmp/usv.msg
upsc server@localhost |grep "input.voltage" |grep "input.voltage:" >> /tmp/usv.msg
upsc server@localhost |grep "output.voltage" |grep "output.voltage:" >> /tmp/usv.msg
upsc server@localhost |grep "ups.status" >> /tmp/usv.msg
cat /tmp/usv.msg | /usr/sbin/ssmtp -au yourusername -ap yourpassword Diese E-Mail-Adresse ist gegen Spam-Bots geschützt, du musst Javascript aktivieren, damit du sie sehen kannst
rm /tmp/usv.msg
else
echo "Subject: USV ONLINE" > /tmp/usv.msg
echo "" >> /tmp/usv.msg
upsc server@localhost |grep "battery.charge" >> /tmp/usv.msg
upsc server@localhost |grep "battery.voltage:" >> /tmp/usv.msg
upsc server@localhost |grep "input.voltage" |grep "input.voltage:" >> /tmp/usv.msg
upsc server@localhost |grep "output.voltage" |grep "output.voltage:" >> /tmp/usv.msg
upsc server@localhost |grep "ups.status" >> /tmp/usv.msg
cat /tmp/usv.msg | /usr/sbin/ssmtp -au yourusername -ap yourpassword Diese E-Mail-Adresse ist gegen Spam-Bots geschützt, du musst Javascript aktivieren, damit du sie sehen kannst
rm /tmp/usv.msg
fi
 
 
... and make it executable: chmod 755 upsmail.sh  
 
Add these lines to /etc/nut/upsmon.conf:  
 

NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYCMD /root/usvmail.sh
 
 
Now you should get an email if your UPS is offline and also if the UPS is back on line power,
I use the sms.at gateway to forward this emails as short message to my mobile. 
Letzte Aktualisierung ( Samstag, 10. Februar 2007 )
 
< Zurück
 
   
© 2023 Markus Layr
Joomla! is Free Software released under the GNU/GPL License.