21 Apr

Monitor TP-Link Smart Plug in check_mk

Objective: to integrate TP-Link Smart Plug into check_mk (for data history and for fun)
Pre-requisite: Check_MK is installed and you have created check_mk site. check_mk installation tutorial will not be covered under this post.

Install software dependencies

apt-get install nodejs npm

Install TP-Link Smart Home API

Switch to OMD site

OMD[home]:~/local/bin$ npm install tplink-smarthome-api

Install TP-Link power monitoring plugin

OMD[home]:~/tmp/wget https://mathias-kettner.com/check_mk-exchange-file.php?&file=tp-link-cmk-1.0.mkp

OMD[home]:~/mkp install /tmp/tp-link-cmk-1.0.mkp

Create monitoring host

Go to WATO > Host & Service Parameters > Datasource Programs

Go to Individual program call instead of agent access

Create new rule. You may insert the rule description and comments as needed (optional). Specify this command under INDIVIDUAL PROGRAM CALL INSTEAD OF AGENT ACCESS.
tp-link-power.js $HOSTNAME$

To be safe during test, you may hardcode explicitly the smart plug ip address.

Create new host, enter hostname and IP address and click “Save & Finish”. Edit again this node and click Parameters on top.

Expand DATASOURCE PROGRAM and select the custom check from here. Click “Individual program call instead of agent access” and make sure the check is here and valid.

Wait for few minutes and check the service graph.

References:

https://github.com/bmachek/tp-link-cmk
https://mathias-kettner.com/check_mk-exchange-file.php?&file=tp-link-cmk-1.0.mkp
https://mathias-kettner.com/download/Marco_Reale_Check_MK_Beginner_guide.pdf
https://www.npmjs.com/package/tplink-smarthome-api
https://mathias-kettner.com/cms_datasource_programs.html

05 Feb

Munin monitoring on RaspberryPi/DietPi

Here’s the situation. I have an Odroid XU4 and Raspberry Pi, both of them running with DietPi image. The mission is to perform system monitoring for both of the system.

Install Munin server

Ensure that the system is up to date before you start to install Munin, run:

apt-get updateapt-get upgrade

Apache is used to show the Munin pages, the apache fcgid module is required for the Munin graph zoom feature. Install apache and the fcgid module with apt.

apt-get install apache2 libcgi-fast-perl libapache2-mod-fcgid

Enable the fcgid module in apache.

a2enmod fcgid

Install & Configure Munin

To install Munin on DietPi, we do this:

apt-get install munin munin-node munin-plugins-extra 

Next, we must edit the Munin configuration file /etc/munin/munin.conf. Uncomment the dbdirhtmldirlogdirrundir, and tmpldir lines (the default values are fine). We want Munin to use the name raspiblack.local instead of localhost.localdomain in the HTML output, therefore we replace localhost.localdomain with raspiblack.local in the simple host tree section. Without the comments, the changed file looks like this:

nano /etc/munin/munin.conf
# Example configuration file for Munin, generated by 'make build'

# The next three variables specifies where the location of the RRD
# databases, the HTML output, logs and the lock/pid files. They all
# must be writable by the user running munin-cron. They are all
# defaulted to the values you see here.
#
dbdir /var/lib/munin
htmldir /var/cache/munin/www
logdir /var/log/munin
rundir /var/run/munin

# Where to look for the HTML templates
#
tmpldir /etc/munin/templates

# Where to look for the static www files
#
#staticdir /etc/munin/static

# temporary cgi files are here. note that it has to be writable by
# the cgi user (usually nobody or httpd).
#
# cgitmpdir /var/lib/munin/cgi-tmp # (Exactly one) directory to include all files from. includedir /etc/munin/munin-conf.d [...] # a simple host tree
[raspiblack.local]
address 127.0.0.1
use_node_name yes
[XU4.local]
address 192.168.1.6
use_node_name yes [...]

Run these commands to enable and load the configuration into apache.

cd /etc/apache2/conf-enabled/ln -s /etc/munin/apache24.conf munin.confservice apache2 restart

Make sure you comment out the line Require local and add Require all granted and Options FollowSymLinks SymLinksIfOwnerMatch instead (otherwise you will only be able to access the Munin output from localhost):

nano /etc/munin/apache24.conf
Alias /munin /var/cache/munin/www
<Directory /var/cache/munin/www>
 # Require local
 Require all granted
 Options FollowSymLinks SymLinksIfOwnerMatch
 Options None
</Directory>

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
<Location /munin-cgi/munin-cgi-graph>
 # Require local
 Require all granted
 Options FollowSymLinks SymLinksIfOwnerMatch
 <IfModule mod_fcgid.c>
 SetHandler fcgid-script
 </IfModule>
 <IfModule !mod_fcgid.c>
 SetHandler cgi-script
 </IfModule>
</Location>

Restart Apache:

service apache2 restart

Then restart Munin:

service munin-node restart

Install munin node on XU4

apt-get install munin-node munin-plugins-extra 

Edit munin node configuration

nano /etc/munin/munin-node.conf

Change munin node identification and allow probe

host_name XU4.local 
allow ^192\.168\.1\.230$

192.168.1.230 is the address of the munin server

Then restart Munin:

service munin-node restart

Now wait a few minutes so that Munin can produce its first output, and then go to http://munin-server-ip-address/munin/ in your browser, and you see the first statistics.

References:
https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/

https://www.digitalocean.com/community/tutorials/how-to-install-the-munin-monitoring-tool-on-debian-8

Incoming search terms:

  • munin on raspberry i
  • munin raspberry pi
15 Dec

Energy efficient log servers with Raspberry Pi

I have few Raspberry Pi 2 (RPi2) laying around and doing nothing. For this project, I will be building a centralized log server on RPi2 for my home usage.

1. I’m using DietPi for the OS for simple reason, it is extremely lightweight and having the lowest memory footprint. I will not be covering the image installation to the RPi2 sdcard because that is pretty common process and I assume everyone is already know doing that. Get it from here https://dietpi.com/

2. Once DietPi is installed, ssh to it and complete the initial setup and update.

3. I’m using remotesyslog for for the log collector. If you need advance feature, you may explore Graylog2. Follow the remotesyslog installation guide from here https://www.remotesyslog.com/legacy/

4. Configure your devices to send the logs to this remotesyslog.

5. There are 2 ways of viewing the logs, through the CLI and Web UI.

6. Access the remotesyslog by launching any web browser and you may see below screen.

7. SSH to the remotesyslog and run rsview to see the logs form the terminal.

03 Mar

check_mk: problem & solution

Network Topology

Problem:
From Dashboard-Network Topology-click on any nodes and getting this error “It appears as though you do not have permission to view information for any of the services you requested…
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
and check the authorization options in your CGI configuration file.”
Solution:
Edit /omd/sites/xxx/etc/nagios/cgi.cfg, look for below variable and change to * (all authenticated users)
authorized_for_system_information=*
authorized_for_configuration_information=*
authorized_for_system_commands=*
authorized_for_all_services=*
authorized_for_all_hosts=*
authorized_for_all_service_commands=*
authorized_for_all_host_commands=*

Then restart apache

Reference:
http://serverfault.com/questions/502862/nagios-new-user-doesnt-get-enabled-permissions
http://lists.mathias-kettner.de/pipermail/checkmk-en/2014-September/013249.html