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:
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/cca57599-e8f9-40b0-8f83-4778cbfb410a%40googlegroups.com.