{"id":226,"date":"2017-09-15T20:34:21","date_gmt":"2017-09-15T12:34:21","guid":{"rendered":"http:\/\/blog.warbel.net\/?p=226"},"modified":"2017-09-21T12:55:57","modified_gmt":"2017-09-21T04:55:57","slug":"configuring-powershield-ups-on-linux-and-integrating-into-zabbix","status":"publish","type":"post","link":"https:\/\/blog.warbel.net\/index.php\/2017\/09\/15\/configuring-powershield-ups-on-linux-and-integrating-into-zabbix\/","title":{"rendered":"Configuring Powershield UPS on Linux and Integrating into Zabbix"},"content":{"rendered":"<h2>Background:<\/h2>\n<p>Like many IT people in Perth, Australia , I buy my gear for the most part from <a href=\"https:\/\/www.ple.com.au\">PLE computers.<\/a>\u00a0And that includes their uninterruptible power supplies (UPS). The most reasonably priced desktop grade UPS&#8217;s are the Powershield Defender series. Of which I have two:<\/p>\n<ul>\n<li>Power Shield Defender LCD 650VA UPS (requiring the blazer_usb driver)<\/li>\n<li>Power Shield Defender LCD 1.2KVA UPS (requiring the\u00a0usbhid-ups driver)<\/li>\n<\/ul>\n<p>On Windows I would simply plug in the devices and install their drivers. On Linux however, nothing is that simple. This guide will work through connecting and confguring the UPSs on Linux. As it&#8217;s important to know that status of the battery and know when its time to replace them, I also want to be able to monitor my UPSs using my monitoring solution &#8211; Zabbix.<\/p>\n<h2>Install Network UPS Tools<\/h2>\n<p>To get started, install the Network UPS tools.<\/p>\n<pre>sudo apt install nut<\/pre>\n<h2>Identify Your UPS<\/h2>\n<p>The 1.2KVA identifies itself as:<\/p>\n<pre>:~$ lsusb\r\n...\r\nBus 001 Device 003: ID 0764:0501 Cyber Power System, Inc. CP1500 AVR UPS\r\n...<\/pre>\n<p>And the 650KVA reports as:<\/p>\n<pre>:~$ lsusb\r\n...\r\nBus 004 Device 002: ID 0665:5161 Cypress Semiconductor USB to Serial\r\n...<\/pre>\n<h2>Configure NUT<\/h2>\n<p>Edit \/etc\/ups.conf:<\/p>\n<p>As they use different drivers, append the following to the end of the file, replacing the section in the brackets with your own name if you like:<\/p>\n<pre>[defender]\r\n# use either blazer_usb or usbhid-ups depending on your UPS\r\ndriver = blazer_usb\r\nport = auto\r\ndesc = \"Add your description\"<\/pre>\n<p>Edit \/etc\/nut.conf and change:<\/p>\n<pre>MODE=none<\/pre>\n<p>to:<\/p>\n<pre>MODE=standalone<\/pre>\n<p>Add users to the nut-monitor service. These users can change settings on the UPS or simply have read access on them. Edit the file \/etc\/nut\/upsd.users. Un-comment and edit the lines:<\/p>\n<pre>[admin]\r\npassword = yourpassword\r\nactions = SET\r\ninstcmds = ALL\r\n...\r\n [upsmon]\r\n password = yourotherpassword\r\n upsmon master<\/pre>\n<p>Creating the admin account will allow you to test or send commands to the UPS. More on that later.<\/p>\n<p>As the instructions say in the file itself, edit the \/etc\/upsmon.conf file next.\u00a0It is worth reading the options and setting them to your desired state, pay particular attention to the MONITOR section. Append the following to your file:<\/p>\n<pre>MONITOR defender@localhost 1 upsmon yourotherpassword master<\/pre>\n<p>Start the service with and check that everything is working:<\/p>\n<pre>$ sudo service nut-server restart\r\n$ sudo service nut-server status\r\n\u25cf nut-server.service - LSB: Network UPS Tools initscript\r\n Loaded: loaded (\/etc\/init.d\/nut-server; bad; vendor preset: enabled)\r\n Active: active (running) since Fri 2017-09-15 16:08:42 AWST; 4s ago\r\n Docs: man:systemd-sysv-generator(8)\r\n Process: 19871 ExecStop=\/etc\/init.d\/nut-server stop (code=exited, status=0\/SUCCESS)\r\n Process: 19878 ExecStart=\/etc\/init.d\/nut-server start (code=exited, status=0\/SUCCESS)\r\n Tasks: 2\r\n Memory: 2.4M\r\n CPU: 50ms\r\n CGroup: \/system.slice\/nut-server.service\r\n \u251c\u250019906 \/lib\/nut\/usbhid-ups -a defender\r\n \u2514\u250019908 \/lib\/nut\/upsd\r\n\r\nSep 15 16:08:42 atlas systemd[1]: Starting LSB: Network UPS Tools initscript...\r\nSep 15 16:08:42 atlas nut-server[19878]: * Starting NUT - power devices information server and drivers\r\nSep 15 16:08:42 atlas usbhid-ups[19906]: Startup successful\r\nSep 15 16:08:42 atlas upsd[19907]: listening on 127.0.0.1 port 3493\r\nSep 15 16:08:42 atlas upsd[19907]: not listening on ::1 port 3493\r\nSep 15 16:08:42 atlas upsd[19907]: Connected to UPS [defender]: usbhid-ups-defender\r\nSep 15 16:08:42 atlas upsd[19908]: Startup successful\r\nSep 15 16:08:42 atlas nut-server[19878]: ...done.\r\nSep 15 16:08:42 atlas systemd[1]: Started LSB: Network UPS Tools initscript.<\/pre>\n<h2>Testing and Configuring the UPS<\/h2>\n<p>Run the command below to get the current status of the UPS:<\/p>\n<pre> $ sudo upsc defender@localhost<\/pre>\n<p>It will return a long list of values if it is successful.<\/p>\n<p>Run a quick test of the battery with the admin account and check the progress:<\/p>\n<pre>$ sudo upscmd -u admin -p yourpassword defender test.battery.start.quick\u00a0\r\n$ sudo upsc defender@localhost\r\nps.status: OL DISCHRG\r\nups.test.result: In progress\r\n...\r\n$ sudo upsc defender@localhost\r\nups.status: OL CHRG\r\nups.test.result: Done and passed<\/pre>\n<p>More commands for the blazer_usb UPS can be found <a href=\"http:\/\/networkupstools.org\/docs\/man\/blazer_usb.html\">here<\/a>, the test command, at least, also works for the\u00a0usbhid-ups driver too.<\/p>\n<p>Having come this far you should have a basic UPS in a working configuration.<\/p>\n<h1>Configure Zabbix<\/h1>\n<p>download or clone the git repository to your computers with the UPS attached.<\/p>\n<pre>$ git clone\u00a0https:\/\/github.com\/delin\/Zabbix-NUT-Template.git\r\n$ cd Zabbix-NUT-Template<\/pre>\n<p>Copy the files to their proper location:<\/p>\n<pre>$ sudo cp -r sh\/ \/etc\/zabbix\/\r\n$ sudo cp zabbix_agentd.d\/userparameter_nut.conf \/etc\/zabbix\/zabbix_agentd.conf.d\/<\/pre>\n<p>Restart the Zabbix services both on the agent and server.<\/p>\n<pre>sudo service zabbix-agent restart\r\nsudo service zabbix-server restart<\/pre>\n<p>On your desktop, download\/clone the git repository. Log into Zabbix. Follow the instructions and create the value mapping.<\/p>\n<p><a href=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_004.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-241 size-large\" src=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_004-1024x396.png\" alt=\"\" width=\"584\" height=\"226\" srcset=\"https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_004-1024x396.png 1024w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_004-300x116.png 300w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_004-768x297.png 768w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_004-500x193.png 500w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_004.png 1674w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>Import the Zabbix template. In the usual way and link it to your servers.<\/p>\n<p>If you feel like it, create a new screen to monitor your UPS.<\/p>\n<p><a href=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_001.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-245\" src=\"http:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_001-1024x458.png\" alt=\"\" width=\"584\" height=\"261\" srcset=\"https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_001-1024x458.png 1024w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_001-300x134.png 300w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_001-768x344.png 768w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_001-500x224.png 500w, https:\/\/blog.warbel.net\/wp-content\/uploads\/2017\/09\/Selection_001.png 1213w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>And you&#8217;re done! No more guessing and hoping your UPS&#8217;s haven&#8217;t swapped to battery when you&#8217;re away from home.<\/p>\n<h2>Troubleshooting:<\/h2>\n<p>&nbsp;<\/p>\n<p>The Powershield UPS that uses the driver\u00a0usbhid-ups has a habit of dropping out, with the error message that the data is stale. I attempted\u00a0 a work around with a script with the following in \/root\/restart_service.sh:<\/p>\n<pre>#!\/bin\/sh\r\n#Get the error state:\r\nErrorState=`upsc defender@localhost 2&gt;&amp;1|grep -v SSL|cut -b 1-5|tail -1`;\r\n#If the error state is equal to \"Error\" then restart the service\r\nif [ $ErrorState = \"Error\" ]\r\nthen\r\n service nut-server restart\r\n echo \"Restarting nut-server\" &gt;&gt; \/var\/log\/syslog\r\nfi<\/pre>\n<p>And edited the crontab for root with sudo crontab -e and add the following line:<\/p>\n<pre>* * * * * \/bin\/bash -l -c \"\/root\/restart_service.sh; sleep 30 ; \/root\/restart_service.sh\"<\/pre>\n<p>Unfortunately this did not resolve my issue! Eventually I played around with a few settings, ultimately arriving at adjusting the maxretry in ups.conf. Changing it to:<\/p>\n<pre>maxretry=5<\/pre>\n<p>I also adjusted the polling interval to 60 seconds.<\/p>\n<h2>Resources:<\/h2>\n<p>Big thanks to\u00a0<a href=\"http:\/\/nitestick.net\/nut-for-defender-1200\/\">http:\/\/nitestick.net\/nut-for-defender-1200\/<\/a> whom I mostly followed to get this working.<br \/>\nBlazer USB documentation: <a href=\"http:\/\/networkupstools.org\/docs\/man\/blazer_usb.html\">http:\/\/networkupstools.org\/docs\/man\/blazer_usb.html<\/a><br \/>\nZabbix NUT templates:\u00a0<a href=\"https:\/\/github.com\/delin\/Zabbix-NUT-Template\">https:\/\/github.com\/delin\/Zabbix-NUT-Template<br \/>\n<\/a>NUT documentation page, which helped me to narrow down the drivers I needed:\u00a0<a href=\"http:\/\/networkupstools.org\/stable-hcl.html\">http:\/\/networkupstools.org\/stable-hcl.html<br \/>\n<\/a>I also referenced:\u00a0<a href=\"http:\/\/tedfelix.com\/software\/nut-network-ups-tools.html\">http:\/\/tedfelix.com\/software\/nut-network-ups-tools.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background: Like many IT people in Perth, Australia , I buy my gear for the most part from PLE computers.\u00a0And that includes their uninterruptible power supplies (UPS). The most reasonably priced desktop grade UPS&#8217;s are the Powershield Defender series. Of &hellip; <a href=\"https:\/\/blog.warbel.net\/index.php\/2017\/09\/15\/configuring-powershield-ups-on-linux-and-integrating-into-zabbix\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[21,24,25,23,17],"class_list":["post-226","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-monitoring","tag-nut","tag-power","tag-ups","tag-zabbix"],"_links":{"self":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts\/226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/comments?post=226"}],"version-history":[{"count":15,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts\/226\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/posts\/226\/revisions\/252"}],"wp:attachment":[{"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/categories?post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.warbel.net\/index.php\/wp-json\/wp\/v2\/tags?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}