but get error of DBI not installed (perl DBI::Sqlite3 module), and I can not figured-out.
#!/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();
apt-get install libdbd-sqlite3-perl