$sudo apt-get install apcupsd
#!/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
apcupsd-ippon0.events
apcupsd-ippon0.status
apcupsd-ippon1.events
apcupsd-ippon1.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>
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
#!/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
UserParameter=apcupsd[*],/usr/lib/zabbix/externalscripts/apcupsd $1 $2
$sudo service zabbix-server restart
Do not abuse external checks! They can lead to a significant decrease in the performance of Zabbix system.
#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; }
gcc apcupsd.c -o apcupsd -std=c99
Source: https://habr.com/ru/post/275535/
All Articles