/usr/share/perl5/NagiosGrapher/Hooks/NG2MySQL.pm is in nagiosgrapher 1.7.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | package NagiosGrapher::Hooks::NG2MySQL;
# Database Structure: see under srcdir/tools/ng2mysql_create_db.sql
#
use NagiosGrapher::Hooks::Generic;
use vars qw (
@ISA
);
@ISA = ('NagiosGrapher::Hooks::Generic');
sub init {
$self = shift;
$self->SetTypes (
'before_rrdupdate',
);
return $self->SUPER::init(@_);
}
sub prepare {
my $self = shift;
use Data::Dumper;
use DBI;
my $rc = 1;
$self->print_log("Log2Mysql: ". $self->Host." - ".$self->Service);
$self->{'dbh'}=DBI->connect("DBI:mysql:nagiosgrapher:localhost","nguser","ngpasswd");
if(!$self->{'dbh'}) {
$self->print_log("Log2Mysql: cannot connect to database!");
$rc=0;
} else {
$self->{'sth'}=$self->{'dbh'}->prepare("INSERT INTO servicevalues SET host=?,service=?,label=?,value=?");
}
return $rc;
}
sub commit {
my $self = shift;
my $values = $self->Values;
foreach (keys %{ $self->{Values} }) {
$self->{'sth'}->execute($self->Host,$self->Service,$_,$self->{Values}->{$_});
}
return 1;
}
sub cleanup {
my $self = shift;
$self->{'dbh'}->disconnect;
return 1;
}
1;
|