Skip to content

Instantly share code, notes, and snippets.

@kmpm
Last active February 22, 2018 16:17
Show Gist options
  • Save kmpm/99761b40b6f17600d3f84b5fa7f8e1b6 to your computer and use it in GitHub Desktop.
Save kmpm/99761b40b6f17600d3f84b5fa7f8e1b6 to your computer and use it in GitHub Desktop.
My Raspberry Pi Jessie notes

My Raspberry Pi (Raspbian Jessie) Notes

All this was made on an RPi 3 running raspbian lite.

Locale

English with Swedish formatting of numbers, dates, times, Monday as first day of week etc.

wget http://www.stacken.kth.se/~auno/en_SE
sudo cp en_SE /usr/share/i18n/locales/en_SE
sudo localedef -i en_SE -f UTF-8 en_SE.UTF-8
sudo su -c "echo 'en_SE.UTF-8 UTF-8' >> /etc/locale.gen"
sudo locale-gen

Change /etc/default/locale to en_SE.UTF-8

Static IP

sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.backup
sudo vim /etc/dhcpcd.conf

Add following to the TOP of the file, adapt to your environment.

interface eth0
 static ip_address=10.3.2.8/24
 static routers=10.3.2.1
 static domain_name_servers=8.8.8.8

Zabbix Proxy and Agent

https://www.zabbix.org/wiki/Zabbix_on_the_Raspberry_Pi_(OS_Raspbian)

From deb

https://github.com/imkebe/zabbix3-rpi

sudo apt-get install -y snmp-mibs-downloader fping curl
wget https://github.com/imkebe/zabbix3-rpi/raw/master/zabbix-proxy-sqlite3_3.0.2-1%2Bjessie_armhf.deb
sudo dpkg -i zabbix-proxy-sqlite3_3.0.2-1+jessie_armhf.deb'
sudo apt-get install -f

wget https://github.com/imkebe/zabbix3-rpi/raw/master/zabbix-agent_3.0.2-1%2Bjessie_armhf.deb
sudo dpkg -i zabbix-agent_3.0.2-1+jessie_armhf.deb

gzip -d /usr/share/doc/zabbix-proxy-sqlite3/schema.sql.gz -c > schema.sql
sudo mkdir /var/lib/zabbix
sudo sqlite3 /var/lib/zabbix/zabbix.db < schema.sql
sudo chown -R zabbix:zabbix /var/lib/zabbix

From source

sudo groupadd zabbix
sudo useradd -g zabbix -d /usr/local/share/zabbix -s /bin/false zabbix
sudo usermod -aG www-data zabbix 
sudo apt-get install -y snmp-mibs-downloader fping curl sqlite3 libsqlite3-dev libxml2-dev libsnmp-base libsnmp-dev libssh2-1-dev libcurl4-gnutls-dev checkinstall

wget -O zabbix-3.0.4.tar.gz http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.4/zabbix-3.0.4.tar.gz?r=http%3A%2F%2Fwww.zabbix.com%2Fdownload.php&ts=1475137986&use_mirror=vorboss

tar -zxf zabbix-3.0.4.tar.gz
cd zabbix-3.0.4
./configure --enable-proxy --enable-agent --with-sqlite3 \
  --with-net-snmp --with-libcurl --with-libxml2 --with-ssh2 \
  --prefix=/usr --sysconfdir=/etc/zabbix
  
make
sudo -k checkinstall --fstrans=no \
  --pkgsource="http://www.zabbix.com" \
  --nodoc \
  --pkgversion="3.0.5" \
  --pkgrelease="1" \
  --pkgname=zabbix \
  --requires=snmp-mibs-downloader,fping,curl,sqlite3,libsqlite3-dev,libxml2-dev,libsnmp-base,libsnmp-dev,libssh2-1-dev,libcurl4-gnutls-dev \
  --provides=zabbix-agent,zabbix-proxy-sqlite3


#importing the schema below can take a couple of minutes
cd database/sqlite3
sudo mkdir /var/lib/zabbix
sudo sqlite3 /var/lib/zabbix/zabbix.db < schema.sql
#proxy only needs schema

sudo chown -R zabbix:zabbix /var/lib/zabbix
sudo mkdir /var/log/zabbix
sudo chown zabbix /var/log/zabbix

Edit /etc/zabbix/zabbix_proxy.conf

Server=<your server ip>
ServerPort=<your port>
Hostname=<your hostname>
LogFile=/var/log/zabbix/zabbix_proxy.log
PidFile=/var/run/zabbix/zabbix_proxy.pid
DBName=/var/lib/zabbix/zabbix.db
FpingLocation=/usr/bin/fping

Edit /etc/zabbix/zabbix_agentd.conf

Hostname=<your hostname>
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log

To enable and activate the services. Add the .service files included to /etc/systemd/system and do the following.

#add files below to /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable zabbix-proxy-sqlite3.service
sudo systemctl start zabbiz-proxy-sqlite3.service

sudo systemctl enable zabbix-agent.service
sudo systemctl start zabbix-agent.service

Read OWFS temperatures using SNMP

OWFS

sudo apt-get install i2c-tools owfs ow-shell

Edit /boot/config.txt

dtparam=i2c_arm=on
dtparam=i2c1=on

Edit /etc/modules

i2c-dev

If you want to access I2C devices from userland then you need dtparam=i2c_arm=on in /boot/config.txt and i2c-dev in /etc/modules. Make sure i2c_bcm2708 is not in /etc/modules. Device tree will automatically load i2c_bcm2708 (it will not load i2c_dev).

Configure OWFS

#/etc/owfs.conf
server: i2c = ALL:ALL

Test

pi@raspberrypi ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- 1b -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

If you find the 1b then in my case a 1-wire i2c interface was found.

sudo service owserver restart

sudo owget
/28.455B92070000
/bus.0
/uncached
/settings
/system
/statistics
/structure
/simultaneous
/alarm

SNMP

Preparations

  • sudo apt-get install snmpd snmp-mibs-downloader
  • working owfs configuration

Setup

Add the following to the file /usr/local/bin/get-temp.sh

#!/bin/bash

#usage get-temp.sh 10.658A92010800 temperature9

SENSOR=$1
VALUE=$2

if [ -z "$VALUE" ]; then
        VALUE=temperature
fi

OUTPUT=$(owread /$SENSOR/$VALUE)
echo $OUTPUT

Make it executable.

sudo chmod +x /usr/local/bin/get-temp.sh

Edit /etc/snmp/snmpd.conf and extend the SNMP.

#if you omit the temperature9 value it will default to just temperature
#the strange number is the ID of the device.
extend temp1 /usr/local/bin/get-temp.sh 28.455B92070000 temperature9

In the same file you will need to give more access to at least localhost.

#Uncomment the line close to the top of the file
#rocommunity public  localhost

#so that is reads
rocommunity public  localhost

Verify

# restart service to load new config
sudo service snmpd restart

# translate one named into numeric oid
snmptranslate -On NET-SNMP-EXTEND-MIB::nsExtendOutputFull.\"temp1\"
> .1.3.6.1.4.1.8072.1.3.2.3.1.2.5.116.101.109.112.49

# walk the tree, from extensions
snmpwalk -v2c -c public localhost NET-SNMP-EXTEND-MIB::nsExtendObjects
> NET-SNMP-EXTEND-MIB::nsExtendNumEntries.0 = INTEGER: 2
> NET-SNMP-EXTEND-MIB::nsExtendCommand."temp1" = STRING: /usr/local/bin/get-temp.sh
> NET-SNMP-EXTEND-MIB::nsExtendCommand."temp2" = STRING: /usr/local/bin/get-temp.sh
> NET-SNMP-EXTEND-MIB::nsExtendArgs."temp1" = STRING: 28.455B92070000 temperature
> NET-SNMP-EXTEND-MIB::nsExtendArgs."temp2" = STRING: 28.1E4692070000 temperature
> NET-SNMP-EXTEND-MIB::nsExtendInput."temp1" = STRING:
> NET-SNMP-EXTEND-MIB::nsExtendInput."temp2" = STRING:
> NET-SNMP-EXTEND-MIB::nsExtendCacheTime."temp1" = INTEGER: 5
> NET-SNMP-EXTEND-MIB::nsExtendCacheTime."temp2" = INTEGER: 5
> NET-SNMP-EXTEND-MIB::nsExtendExecType."temp1" = INTEGER: exec(1)
> NET-SNMP-EXTEND-MIB::nsExtendExecType."temp2" = INTEGER: exec(1)
> NET-SNMP-EXTEND-MIB::nsExtendRunType."temp1" = INTEGER: run-on-read(1)
> NET-SNMP-EXTEND-MIB::nsExtendRunType."temp2" = INTEGER: run-on-read(1)
> NET-SNMP-EXTEND-MIB::nsExtendStorage."temp1" = INTEGER: permanent(4)
> NET-SNMP-EXTEND-MIB::nsExtendStorage."temp2" = INTEGER: permanent(4)
> NET-SNMP-EXTEND-MIB::nsExtendStatus."temp1" = INTEGER: active(1)
> NET-SNMP-EXTEND-MIB::nsExtendStatus."temp2" = INTEGER: active(1)
> NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."temp1" = STRING: 19.5625
> NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."temp2" = STRING: 19.375
> NET-SNMP-EXTEND-MIB::nsExtendOutputFull."temp1" = STRING: 19.5625
> NET-SNMP-EXTEND-MIB::nsExtendOutputFull."temp2" = STRING: 19.375
> NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."temp1" = INTEGER: 1
> NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."temp2" = INTEGER: 1
> NET-SNMP-EXTEND-MIB::nsExtendResult."temp1" = INTEGER: 0
> NET-SNMP-EXTEND-MIB::nsExtendResult."temp2" = INTEGER: 0
> NET-SNMP-EXTEND-MIB::nsExtendOutLine."temp1".1 = STRING: 19.5625
> NET-SNMP-EXTEND-MIB::nsExtendOutLine."temp2".1 = STRING: 19.375

In the output above temp1 is 19.5625 degrees and temp2 is 19.375.

Reading SNMP Temperatures from Zabbix

Host

  • Create a host with information for the SNMP interface

Host Item

  • Add Item to host.
Name: Something descriptive
Type: SNMPv2 agent

# can be anything unique to the host but keep descriptive
Key: temperature-temp1

Host interface: (select the appropriate interface)

# Change to whatever is appropriate for how your sensor + snmp is configured
SNMP OID: NET-SNMP-EXTEND-MIB::nsExtendOutputFull."temp1"

# change to whatever is set up in /etc/snmpd.conf
SNMP community: public

Type of information: Numeric (float)

# optional but recommended
Units: 'c

# The rest is optional but you could check for example Update Interval
# which should be something like 60 seconds or higer, the sensors
# are quite slow to update.

Host Trigger

Add Trigger to host

# This is just an example
Name: High Temperature UPS-RUM

# The following uses <host>:<item key> and triggers if the last value
# is above 29.
Expression: {01zb03:temperature-temp1.last()}>29

# The following will trigger above 26 and reset when 
# below 23 for at least 2 minutes.
Expression:
({TRIGGER.VALUE}=0 and {01zb03:temperature-temp1.last()}>26)
or 
({TRIGGER.VALUE}=1 and {01zb03:temperature-temp1.max(2m)}>23)
[Unit]
Description=Zabbix Monitor Agent
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/sbin/zabbix_agentd
PIDFile=/run/zabbix/zabbix_agentd.pid
RuntimeDirectory=zabbix
User=zabbix
PrivateTmp=yes
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=Zabbix Sqlite Proxy
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/run/zabbix/zabbix_proxy.pid
User=zabbix
PrivateTmp=yes
PermissionsStartOnly=true
RuntimeDirectory=zabbix
ExecStart=/usr/sbin/zabbix_proxy
[Install]
WantedBy=multi-user.target
sudo apt install libsnmp-perl libnet-snmp-perl snmptrapd
vim /etc/snmp/snmptrapd.conf

#Add following
authCommunity execute <your community string>
perl do "/usr/local/bin/zabbix_trap_receiver.pl";


sudo snmptrapd -f -Lo -c /etc/snmp/snmptrapd.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment