Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Cubietruck Battery monitor with nagios

Featured Replies

hi all,

if someone need, I adapted for nagios the script to monitor battery cubietruck.

The script is pnp4nagios friendly.

#!/bin/bash
######################################################################################
#
# Battery info
#


/usr/sbin/i2cset -y -f 0 0x34 0x82 0xC3
# read power OPERATING MODE register @01h
POWER_OP_MODE=$(/usr/sbin/i2cget -y -f 0 0x34 0x01)
BAT_EXIST=$(($(($POWER_OP_MODE&0x20))/32))  # divide by 32 is like shifting rigth 5 times
CHARG_IND=$(($(($POWER_OP_MODE&0x40))/64))  # divide by 64 is like shifting rigth 6 times

########################################################################################
#read battery voltage   79h, 78h        0 mV -> 000h,   1.1 mV/bit      FFFh -> 4.5045 V
BAT_VOLT_LSB=$(/usr/sbin/i2cget -y -f 0 0x34 0x79)
BAT_VOLT_MSB=$(/usr/sbin/i2cget -y -f 0 0x34 0x78)

BAT_BIN=$(( $(($BAT_VOLT_MSB << 4)) | $(($(($BAT_VOLT_LSB & 0xF0)) >> 4)) ))
BAT_VOLT=$(echo "($BAT_BIN*1.1)"|bc)

# store maximum battery voltage to compare to
if [ -f "/etc/default/battery" ]; then
        source "/etc/default/battery"
else
        echo "MAX=$BAT_VOLT" > /etc/default/battery
	echo "MIN=3484" >> /etc/default/battery
fi

# integer is enough, cut down the decimals
MAX=${MAX%.*}
BAT_VOLT=${BAT_VOLT%.*}

# mainline kernel shows battery existence even if not exists. this is walkaround 
if [ "$BAT_VOLT" -ge "3200" ]; then


# if we have new max value, alter defaults
if [ "$BAT_VOLT" -gt "$MAX" ]; then 
MAX=$BAT_VOLT
sed -e 's/MAX=.*/MAX='$BAT_VOLT'/g' -i /etc/default/battery
fi

# if we have new min value, alter defaults
if [ "$BAT_VOLT" -lt "$MIN" ]; then
MIN=$BAT_VOLT
sed -e 's/MIN=.*/MIN='$BAT_VOLT'/g' -i /etc/default/battery
fi

# calculate percentage
percent=$(echo "($BAT_VOLT-$MIN)*100/($MAX-$MIN)"|bc)
fi

# define output format
output="Load : $percent% | Load_Batt=$percent;80;35;3.4;4.2;"

# if load% in range 80-10 ok
if [ "$percent" -ge 80 -a "$percent" -le 100 ]; then 
	echo "OK- $output"
	exit 0
# if load % in range 40-79 warning
elif [ "$percent" -ge 40 -a "$percent" -le 79 ]; then 
	echo "WARNING - $output" 
	exit 1
# if load % in range 0-39 critical
elif [ "$percent" -ge 0 -a "$percent" -le 39 ]; then 
	echo "CRITICAL - $output" 
	exit 2
# if check non riceve data
else	echo "UNKNOW"
        exit 3
fi

if run script for non admin user need add permission to  /usr/sbin/iscget

ex:

chmod 777 /usr/sbin/iscget

and change default permission for /dev/i2c-0

ex:

sudo nano /lib/udev/rules.d/60-i2c-tools.rules 
KERNEL=="i2c-0"     , GROUP="i2c", MODE="0660"

to

KERNEL=="i2c-0"     , GROUP="i2c", MODE="0666"

and reboot

 

 

 

post-432-0-60078400-1445345677_thumb.png

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.