# shellcheck shell=bash # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0-or-later # netdata # real-time performance and health monitoring, done right! # (C) 2016 Costa Tsaousis # apcupsd_ip= apcupsd_port= declare -A apcupsd_sources=( ["local"]="127.0.0.1:3551" ) # how frequently to collect UPS data apcupsd_update_every=10 apcupsd_timeout=3 # the priority of apcupsd related to other charts apcupsd_priority=90000 apcupsd_get() { run -t $apcupsd_timeout apcaccess status "$1" } is_ups_alive() { local status status="$(apcupsd_get "$1" | sed -e 's/STATUS.*: //' -e 't' -e 'd')" case "$status" in "" | "COMMLOST" | "SHUTTING DOWN") return 1 ;; *) return 0 ;; esac } apcupsd_check() { # this should return: # - 0 to enable the chart # - 1 to disable the chart require_cmd apcaccess || return 1 # backwards compatibility if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ]; then apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}" fi local host working=0 failed=0 for host in "${!apcupsd_sources[@]}"; do apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null # shellcheck disable=2181 if [ $? -ne 0 ]; then error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}." failed=$((failed + 1)) else if ! is_ups_alive ${apcupsd_sources[${host}]}; then error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online." failed=$((failed + 1)) else working=$((working + 1)) fi fi done if [ ${working} -eq 0 ]; then error "No APC UPSes found available." return 1 fi return 0 } apcupsd_create() { local host for host in "${!apcupsd_sources[@]}"; do # create the charts cat <