#!/bin/bash

if [ $(CreoleGet activer_nut) = "oui" ] && [ $(CreoleGet nut_ups_daemon) = "oui" ]; then
    . /usr/lib/eole/diagnose.sh
    nut_ups_name=$(CreoleGet nut_ups_name)
    EchoGras "*** Onduleur"
    printf ".  %${len_pf}s => " "Test de l'onduleur"
    status=`/bin/upsc $nut_ups_name@localhost ups.status 2>&1`
    if [ $? -ne 0 ];then
        EchoRouge "$status"
    else
        charge=`/bin/upsc $nut_ups_name@localhost battery.charge | cut -d'.' -f1`
        #si OL dans le status
        for a in $status; do
            [ "$a" = "OL" ] && ok=true && break
        done

        if [ "$ok" = "true" ]; then
            EchoVert "OK ($charge%)"
        elif [ "$charge" -lt "20" ]; then
            EchoRouge "Charge batterie faible ($charge%)"
        else
            EchoOrange "Fonctionnement sur batterie ($charge%)"
        fi
    fi
    echo
fi
