Monitoring WeeWX with Nagios

219 views
Skip to first unread message

Maarten van der Hoeven

unread,
Jun 19, 2019, 2:50:30 AM6/19/19
to weewx-user
I want to monitor the WeeWX-process, whether that process is alive or not. To monitor things (such as http-servers, mysql-database, down-/uplink internet-connection, etc), I am using Nagios.

I am wondering if someone already has written a Nagios-plugin to monitor the WeeWX-process, and is willing to share that plugin.

Andy

unread,
Jun 19, 2019, 9:44:31 AM6/19/19
to weewx-user

I am just using out of the box checks for now. Maybe a log file monitor to make sure there are specific terms in the log (or not in the log) would be good 

Xant

unread,
May 21, 2020, 4:58:31 PM5/21/20
to weewx-user

Also in the search of Nagios plugin for WeeWX monitoring.

Found the following:


but get error of DBI not installed (perl DBI::Sqlite3 module), and I can not figured-out.

Posting in case someone already have a working plugin, update or can look on the above.

Xant

Xant

unread,
May 21, 2020, 5:08:12 PM5/21/20
to weewx-user

Turned-out the above is Matthew Wall page... maybe Matt can clarify.

vince

unread,
May 21, 2020, 5:11:59 PM5/21/20
to weewx-user
On Thursday, May 21, 2020 at 1:58:31 PM UTC-7, Xant wrote:
but get error of DBI not installed (perl DBI::Sqlite3 module), and I can not figured-out.



The perl code requires a CPAN module so it can talk to the sqlite3 db

Look at the bottom of the comment block at the top of check_wview for instructions

Maarten van der Hoeven

unread,
May 22, 2020, 4:51:22 AM5/22/20
to weewx-user
What I am doing now, is checking how 'old'  the latest records are in the MySQL-database. If the last 10 minutes no records are found, then there must be something wrong. perl-script:

#!/usr/bin/perl  -w

use strict;

use DBI;

#definition of variables

my $db="weewx";

my $host="x.x.x.x";

my $user="username";

my $password=”password";

my $interval = 10;

my $max_minutes_behind_now = 5;

my $time = localtime time;

my $pretime = localtime (time - $interval * 60);

 

my $state = "OK";

 

my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);

 

#connect to MySQL database

my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host",$user,$password, {PrintError => 0});

 

if (!$dbh) {

        print "CRITICAL ERROR - Unable to connect to database $db with user $user - $DBI::errstr";

        exit $ERRORS{"CRITICAL"};

}

 

my $stmt = "SELECT datetime

            FROM archive

            WHERE from_unixtime(dateTime) < localtime

               && from_unixtime(dateTime) > DATE_SUB(NOW(), INTERVAL $interval MINUTE) ORDER BY dateTime desc LIMIT 20";

 

#prepare the query

my $sth = $dbh->prepare($stmt);

 

#execute the query

if (!$sth->execute()) {

        print "CRITICAL ERROR - Unable to execute query on $db";

        exit $ERRORS{"CRITICAL"};

}

 

my $results = $sth->rows;

 

if ($sth->err()) {

        print "CRITICAL ERROR - Error in retrieving results on $db";

        exit $ERRORS{"CRITICAL"};

}

 

#Check for new entry count

if ($results >= $max_minutes_behind_now) {

        print "OK - $results records within last $interval minutes";

        $state = "OK";

} else {

        print "CRITICAL - only $results records within last $interval minutes";

        $state = "CRITICAL";

}

 

$sth->finish();

$dbh->disconnect();


 

Op donderdag 21 mei 2020 23:11:59 UTC+2 schreef vince:

Xant

unread,
May 22, 2020, 2:57:31 PM5/22/20
to weewx-user

Vince

You correct, and apologies to MWall for missing the remarks.

To note, there is a typo, or later name change (missing a 'd'):

apt-get install libdbd-sqlite3-perl

No longer DBI error, but still issues. I will keep posted, or try Maarten script.

Xant

unread,
May 23, 2020, 10:15:25 PM5/23/20
to weewx-user
Update

Matthew Wall nagios plugin works.

Rob Cranfill

unread,
Mar 5, 2022, 9:33:04 PM3/5/22
to weewx-user
I would like to monitor WeeWX with Nagios, too, but find the referenced page no longer there ("This site can't be reached"). If this isn't just a temporary outage, does anyone know where else this code might be found? I think I found his GitHub page but it's not there, I think.
Reply all
Reply to author
Forward
0 new messages