{
date: ' 2017-11-14 23',
upsname: ' ups01',
status: ' ONLINE',
loadpct: ' 44.2 Percent',
bcharge: ' 100.0 Percent',
timeleft: ' 28.0 Minutes'
}
Last active
July 6, 2020 07:36
-
-
Save RolfKoenders/760cf8cccf04b7696b208b6b724fa1a3 to your computer and use it in GitHub Desktop.
Parse the output of 'apcaccess status` to something usable in node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const lineReader = require('readline'); | |
const fs = require('fs'); | |
const FIELDS = ['DATE', 'UPSNAME', 'STATUS', | |
'LOADPCT', 'BCHARGE', 'TIMELEFT']; | |
let OUTPUT = {}; | |
const reader = lineReader.createInterface({ | |
input: fs.createReadStream('example-status.txt') | |
}); | |
reader.on('line', (line) => { | |
const splitLine = line.split(':'); | |
const field = splitLine[0].trim(); | |
if (FIELDS.indexOf(field) > -1) { | |
OUTPUT[field.toLowerCase()] = splitLine[1]; | |
} | |
}).on('close', () => { | |
console.log('Gathered Data: \n', OUTPUT); | |
process.exit(0); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APC : 001,050,1135 | |
DATE : 2017-11-14 23:40:05 +0100 | |
HOSTNAME : node01 | |
VERSION : 3.14.12 (29 March 2014) debian | |
UPSNAME : ups01 | |
CABLE : Custom Cable Smart | |
DRIVER : APC Smart UPS (any) | |
UPSMODE : Stand Alone | |
STARTTIME: 2017-11-14 23:02:53 +0100 | |
MODEL : Smart-UPS 1500 | |
STATUS : ONLINE | |
LINEV : 234.7 Volts | |
LOADPCT : 44.2 Percent | |
BCHARGE : 100.0 Percent | |
TIMELEFT : 28.0 Minutes | |
MBATTCHG : 25 Percent | |
MINTIMEL : 3 Minutes | |
MAXTIME : 0 Seconds | |
MAXLINEV : 234.7 Volts | |
MINLINEV : 233.2 Volts | |
OUTPUTV : 234.7 Volts | |
SENSE : High | |
DWAKE : 0 Seconds | |
DSHUTD : 180 Seconds | |
DLOWBATT : 2 Minutes | |
LOTRANS : 208.0 Volts | |
HITRANS : 253.0 Volts | |
RETPCT : 15.0 Percent | |
ITEMP : 24.3 C | |
ALARMDEL : 5 Seconds | |
BATTV : 27.7 Volts | |
LINEFREQ : 50.0 Hz | |
LASTXFER : Automatic or explicit self test | |
NUMXFERS : 0 | |
TONBATT : 0 Seconds | |
CUMONBATT: 0 Seconds | |
XOFFBATT : N/A | |
SELFTEST : NO | |
STESTI : 336 | |
STATFLAG : 0x05000008 | |
REG1 : 0x00 | |
REG2 : 0x00 | |
REG3 : 0x00 | |
MANDATE : 04/26/05 | |
SERIALNO : AS0518121231 | |
BATTDATE : 04/26/05 | |
NOMOUTV : 230 Volts | |
NOMBATTV : 24.0 Volts | |
EXTBATTS : 0 | |
FIRMWARE : 601.3.I | |
END APC : 2017-11-14 23:40:57 +0100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment