📜 ⬆️ ⬇️

Monitoring uninterruptible power supply ippon winner 3000 using apcupsd + Zabbix in Ubuntu

What prompted me to write this article? Searching on the Internet for "monitoring ippon winner 3000". The Internet gave as a rule articles about configuring NUT . The project is really interesting, it has many features. But there is one small BUT! Not supported ippon winner 3000 via USB. On the COM port, everything works fine. I saw the configs connect via USB, but it seems to me it is a copy-paste without practical verification. Although maybe I'm wrong. I at least killed half a day trying to make it work, but in vain.

Found an alternative project apcupsd , everything started from a box with small settings. I have one ippon winner 3000 connected via USB to one computer whose task is responsible for monitoring. It also contains Zabbix. We will not go into the details of Zabbix, I will only say that it is worthy of a separate article and not one. I don’t see the point of the process of writing; Just bring ready configs. Install the package itself:
$sudo apt-get install apcupsd

All configuration files and default scripts are in / etc / acpupsd by default. Please pay special attention to the names of the status and configuration files.

apcupsd-ippon0.conf
UPSCABLE usb
UPSTYPE usb
DEVICE / dev / usb / hiddev0
LOCKFILE / var / lock
SCRIPTDIR / etc / apcupsd
PWRFAILDIR / etc / apcupsd
NOLOGINDIR / etc
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 127.0.0.1
NISPORT 3551
EVENTSFILE /var/log/apcupsd/apcupsd-ippon0.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 60
STATFILE /var/log/apcupsd/apcupsd-ippon0.status
LOGSTATS off
DATATIME 0

apcupsd-ippon1.conf
UPSCABLE usb
UPSTYPE usb
DEVICE / dev / usb / hiddev1
LOCKFILE / var / lock
SCRIPTDIR / etc / apcupsd
PWRFAILDIR / etc / apcupsd
NOLOGINDIR / etc
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 0
ANNOY 300
ANNOYDELAY 60
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 127.0.0.1
NISPORT 3552
EVENTSFILE /var/log/apcupsd/apcupsd-ippon1.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 60
STATFILE /var/log/apcupsd/apcupsd-ippon1.status
LOGSTATS off
DATATIME 0


To start using a simple script
apcups-start.sh
 #!/bin/bash [ -n "`pgrep apcupsd`" ] && killall apcupsd ; sleep 5 ; UPS_DAEMON="/sbin/apcupsd" for CONF_FILE in /etc/apcupsd/apcupsd*conf do $UPS_DAEMON -f $CONF_FILE echo $UPS_DAEMON -f $CONF_FILE done 


It starts the apcupsd daemon with each apcupsd * conf configuration file. Go to the / var / log / apcupsd directory and examine its contents. If everything went well, its contents should look like this:
')
apcupsd-ippon0.events
apcupsd-ippon0.status
apcupsd-ippon1.events
apcupsd-ippon1.status


From the titles it is clear that the files with the events extension are responsible for daemon events, ala start-stop, etc. For us, files with status extensions are of more interest. I will cite the contents with explanations of one of them. Looking ahead, I’ll say that zabbih’s external processing will take information from these files.

/var/log/apcupsd/apcupsd-ippon0.status
 APC: 001,031,0762 - version number, number of lines, number of bytes
 DATE: 2016-01-19 20:25:01 +0300 - time to receive information from the UPS
 HOSTNAME: zavdiag - DNS server name
 VERSION: 3.14.10 (13 September 2011) debian - build version of apcupsd
 UPSNAME: zavdiag - name from apcupsd.conf
 CABLE: USB Cable - Control Cable Type
 DRIVER: USB UPS Driver - driver name
 UPSMODE: Stand Alone
 STARTTIME: 2016-01-19 14:40:36 +0300 - When the apcupsd daemon started
 MODEL: HID UPS - Model
 STATUS: ONLINE - the current status (ONLINE, ONBATT, NOBATT, etc.), is retrieved from the UPS
 LOADPCT: 12.0 Percent Load Capacity - the load level as a percentage of VA, is extracted from the UPS
 BCHARGE: 100.0 Percent - the percentage of battery charging is removed from the UPS
 TIMELEFT: 62.4 Minutes - Estimated Battery Runtime, Removed from UPS
 MBATTCHG: 5 Percent - the value of BATTERYLEVEL in apcupsd.conf
 MINTIMEL: 3 Minutes - the MINUTES value in apcupsd.conf
 MAXTIME: 0 Seconds - the TIMEOUT value in apcupsd.conf
 OUTPUTV: 216.0 Volts - output voltage, extracted from the UPS
 DWAKE: -01 Seconds - how many seconds UPS will wait after power is restored before the load is turned on, removed from the UPS (I think it is displayed incorrectly)
 LOTRANS: 176.0 Volts - the lower limit of the allowable voltage, is removed from the UPS
 HITRANS: 264.0 Volts - the upper limit of the allowable voltage, is removed from the UPS
 ALARMDEL: 30 seconds - the period of delay in the signal when power is lost, is removed from the UPS
 LINEFREQ: 50.0 Hz - frequency input voltage, extracted from the UPS
 NUMXFERS: 0 - the number of state changes extracted from the UPS
 TONBATT: 0 seconds - the current battery life is retrieved from the UPS
 CUMONBATT: 0 seconds - total battery life, retrieved from UPS
 XOFFBATT: N / A - the time of the last transition to work from battery to network
 SELFTEST: NO - the result of the UPS self-test (OK, BT - low charge, BG - overload, NO - did not start the last 5 minutes), is removed from the UPS
 STATFLAG: 0x07000008 Status Flag - bit status bar, extracted from the UPS
 SERIALNO: S42140618978 - the serial number of the UPS, is removed from the UPS
 NOMPOWER: 2700 Watts - Nominal power in watts (active?), Extracted from the UPS
 END APC: 2016-01-19 20:25:02 +0300 - the time of issuance of the state </ blockquote>


More information can be found here.
There you can also find details on the apcupsd configuration.
Edit script files, enter your email address:

Briefly describe the assignment of scripts:

changeme - called when the battery needs to be replaced
commfailure - called when communication with the block is lost
commok - called when communication with the block is restored
onbatter y - called when switching to barei
offbattery - called when switching from battery
killpower - called before shutdown


This completes the apcupsd setup. If in short, the process goes like this: the daemon polls the UPS devices, calls the appropriate script when the state changes, and generates state files. Now it remains to tie all this to Zabbix.

The only logical way, in my opinion, is to enter data into a zabbih using an external check .

To do this, use a script that will parse the state file and get the values ​​of the specified parameters. In my case, both the agent and the zabbix server will be located on the same computer. The agent listens to port 10050 server 10051. We need to find out the directory where the external audit files are located. To do this, look for the string ExternalScripts = / usr / lib / zabbix / externalscripts in the server configuration file /etc/zabbix/zabbix_server.conf . In this directory and put the file checks. Do not use in any case in the point file name, even if it is a bash script! First, I wrote a script like this:

apcupsd - bash script
 #!/bin/bash if [[ $1 == ippon? ]] && [ -f "/var/log/apcupsd/apcupsd-$1.status" ] ; then case $2 in BCHARGE) cat /var/log/apcupsd/apcupsd-$1.status | grep 'BCHARGE' | awk '{print $3}' ;; OUTPUTV) cat /var/log/apcupsd/apcupsd-$1.status | grep 'OUTPUTV' | awk '{print $3}' ;; LOADPCT) cat /var/log/apcupsd/apcupsd-$1.status | grep 'LOADPCT' | awk '{print $3}' ;; DWAKE) cat /var/log/apcupsd/apcupsd-$1.status | grep 'DWAKE' | awk '{print $3}' ;; STATFLAG) cat /var/log/apcupsd/apcupsd-$1.status | grep 'STATFLAG' | awk '{print $3}' ;; STATUS) cat /var/log/apcupsd/apcupsd-$1.status | grep 'STATUS' | awk '{print $3}' ;; XOFFBATT) cat /var/log/apcupsd/apcupsd-$1.status | grep 'XOFFBATT' | awk '{print $3}' ;; TONBATT) cat /var/log/apcupsd/apcupsd-$1.status | grep 'TONBATT' | awk '{print $3}' ;; TIMELEFT) cat /var/log/apcupsd/apcupsd-$1.status | grep 'TIMELEFT' | awk '{print $3}' ;; esac fi 


In the /etc/zabbix/zabbix_agentd.d directory create the file userparameter_apcupsd.conf with the contents

UserParameter=apcupsd[*],/usr/lib/zabbix/externalscripts/apcupsd $1 $2

Restart agent:
$sudo service zabbix-server restart

However, there is a warning on offsite Zabbix

Do not abuse external checks! They can lead to a significant decrease in the performance of Zabbix system.


And since I am not only admin, but I also write, it was decided to rewrite the external check on C. And who knows when we will rest in this performance.
Create an apcups.c file with the contents:
apcupsd.c
 #include <stdio.h> #include <string.h> #include <unistd.h> char ValueParam[30]; char *GetValue(char *NameVar, char *FileName) { FILE *fconfig=fopen(FileName,"r"); char fileline[255]; unsigned char FLAGDDOT=0,FLAGSPACEB=0; memset(ValueParam,0,sizeof(ValueParam)); while(!feof(fconfig)) { fgets (fileline, 255, fconfig); if(strncmp(fileline,NameVar,strlen(NameVar))==0) { for(int i=0;i<strlen(fileline);i++) { if(fileline[i]!=':' && FLAGDDOT==0) continue; if(FLAGDDOT==0) { FLAGDDOT=1; continue; } if(fileline[i]==' ' && FLAGSPACEB==0) continue; if(fileline[i]==' ' && FLAGSPACEB==1) break; if(FLAGSPACEB==0) FLAGSPACEB=1; ValueParam[strlen(ValueParam)]=fileline[i]; ValueParam[strlen(ValueParam)+1]=0; } if(strlen(ValueParam)>0) break; } } fclose(fconfig); return ValueParam; } void main(int argc, char* argv[]) { //argv[1] - hostname argv[2] - param char fname[255]; //      "ippon"    2  if((argc==3) && (strncmp(argv[1],"ippon",5)==0) ) { memset(fname,0,sizeof(fname)); strcpy(fname,"/var/log/apcupsd/apcupsd-"); strcat(fname,argv[1]); strcat(fname,".status"); //      // /var/log/apcupsd/apcupsd-ipponX.status if(access( fname, F_OK ) != -1) { puts(GetValue(argv[2],fname)); } } return; } 


Compile produce as:
gcc apcupsd.c -o apcupsd -std=c99
The compiled file is stored in / usr / lib / zabbix / externalscripts.

Everything, it remains only to import the template for Zabbix .

I did not set myself the goal of doing something universal, just the opposite, I tried to make the necessary minimum.
In the template are present ( see the description of the parameters above ):
image
For graphs made only 4 parameters:
image
battery charge, current load, output voltage and remaining battery life.

Triggers do not see any reason to start, as the scripts of the apcupsd daemon themselves send a notification to the mail. And the phone with the Internet is always with you. That's all, I will be glad to answer your questions.

After a few more days, I found out very interesting things that I will share with you. Perhaps it will save you from many days of creative torment.

As for the apcupsd project, it is essentially narrowly focused and sharpened mainly under the APC UPS. With it, you are more likely to have devices with a combined USB + COM connection when connected via USB. In my case it was ippon winner 3000. Of the minuses: it does not display the battery charge and temperature. Apparently the APC does not have these parameters.

As for the NUT project, it is more versatile and with it you are more likely to pick up your rare UPS. The main disadvantage with the combined USB + COM connection is only COM!

Source: https://habr.com/ru/post/275535/


All Articles