monitor antrian email dan simpan ke database

#!/usr/bin/perl
#!/usr/bin/env perl
# Script for update IP and system name using nbtscan
# Requirement : perl
# By : s.suyanto@gmail.com

use DBI;
use strict;
use warnings;
use Symbol;
# require “Konfig.pl”;
# print “content-type: text/html \n\n”;

my $hostsms = “serversms”;
my $databasesms = “sms”;
my $usersms = “usersms”;
my $pwsms = “passwordsms”;

my $dbh = DBI->connect(“dbi:mysql:$databasesms:$hostsms:3306”, $usersms, $pwsms);

sub count {
my ($dir) = @_;
my $dh = gensym();
my $c = 0;
opendir($dh, $dir) or die “$0: opendir: $dir: $!\n”;
while (my $f = readdir($dh)) {
if ($f =~ m{^[A-F0-9]{5,}$}) {
++$c;
} elsif ($f =~ m{^[A-F0-9]$}) {
$c += count(“$dir/$f”);
}
}
closedir($dh) or die “closedir: $dir: $!\n”;
return $c;
}
my $qdir = `postconf -h queue_directory`;
chomp($qdir);
chdir($qdir) or die “$0: chdir: $qdir: $!\n”;

my $Masuk = count(“incoming”);
my $Aktif= count(“active”);
my $Ditangguhkan= count(“deferred”);

my $TotalAntrian = $Masuk+$Aktif+$Ditangguhkan;

printf “Incoming: %d\n”, count(“incoming”);
printf “Active: %d\n”, count(“active”);
printf “Deferred: %d\n”, count(“deferred”);
printf “Bounced: %d\n”, count(“bounce”);
printf “Hold: %d\n”, count(“hold”);

if ($TotalAntrian >= 500) {
my $Alert = “Total MailRekind : $TotalAntrian (In : $Masuk, Act: $Aktif, Def: $Ditangguhkan)”;
my $sth = $dbh->prepare(“INSERT INTO `outbox` (`UpdatedInDB`, `InsertIntoDB`, `SendingDateTime`, `SendBefore`, `SendAfter`, `Text`, `DestinationNumber`, `Coding`, `UDH`, `Class`, `TextDecoded`, `MultiPart`, `RelativeValidity`, `SenderID`, `SendingTimeOut`, `DeliveryReport`, `CreatorID`) VALUES (NOW(), NOW(), NOW(), ’23:59:59′, ’00:00:00′, NULL, ‘01111111’, ‘Default_No_Compression’, NULL, 1, ‘$Alert’, ‘false’, -1, NULL, NOW(), ‘default’, ”)”);
$sth->execute();
}

printf “Incoming : $Masuk, Active : $Aktif, Deffered: $Ditangguhkan\n”;

$dbh->disconnect();

By yans008 Posted in Uncategorized

Leave a comment