Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2010-11-02 20:00:53 UTC (rev 5289)
+++ trunk/CHANGES 2010-11-02 22:04:55 UTC (rev 5290)
@@ -41,6 +41,8 @@
New helper table in Runtime database, to speed up configdumpend process on large systems
Added links to Resolve service checks from host edit page and back again
Removed AQL notification method from default install
+ ODW now stores summary statistics of number of hosts/services/serviceresults/perfdata per hour
+ ODW now automatically cleans up failed imports
FIXES:
Fixed new creation of SNMP trap rule type service check redirecting to rules page on create/clone
Modified: trunk/opsview-core/bin/cleanup_import
===================================================================
--- trunk/opsview-core/bin/cleanup_import 2010-11-02 20:00:53 UTC (rev 5289)
+++ trunk/opsview-core/bin/cleanup_import 2010-11-02 22:04:55 UTC (rev 5290)
@@ -100,6 +100,15 @@
" );
$odwdb->do( "
+DELETE performance_hourly_summary
+FROM performance_hourly_summary, performance_labels, hosts
+WHERE start_datetime > FROM_UNIXTIME($last_successful_dataload_timev)
+ AND performance_hourly_summary.performance_label = performance_labels.id
+ AND performance_labels.host = hosts.id
+ AND hosts.opsview_instance_id = $opsview_instance_id
+" );
+
+$odwdb->do( "
DELETE state_history
FROM state_history, servicechecks, hosts
WHERE datetime > FROM_UNIXTIME($last_successful_dataload_timev)
Modified: trunk/opsview-core/bin/db_odw
===================================================================
--- trunk/opsview-core/bin/db_odw 2010-11-02 20:00:53 UTC (rev 5289)
+++ trunk/opsview-core/bin/db_odw 2010-11-02 22:04:55 UTC (rev 5290)
@@ -439,6 +439,11 @@
load_start_timev int NOT NULL,
load_end_timev int,
status ENUM ("running", "failed", "success"),
+ num_hosts INT DEFAULT NULL,
+ num_services INT DEFAULT NULL,
+ num_serviceresults INT DEFAULT NULL,
+ num_perfdata INT DEFAULT NULL,
+ duration INT DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE (period_start_timev, opsview_instance_id),
INDEX (period_end_timev),
@@ -469,7 +474,7 @@
INSERT INTO schema_version (major_release, version) VALUES ('3.0', '4');
INSERT INTO schema_version (major_release, version) VALUES ('3.3', '1');
INSERT INTO schema_version (major_release, version) VALUES ('3.7', '1');
- INSERT INTO schema_version (major_release, version) VALUES ('3.9', '1');
+ INSERT INTO schema_version (major_release, version) VALUES ('3.9', '3');
EOF
}
Modified: trunk/opsview-core/bin/import_runtime
===================================================================
--- trunk/opsview-core/bin/import_runtime 2010-11-02 20:00:53 UTC (rev 5289)
+++ trunk/opsview-core/bin/import_runtime 2010-11-02 22:04:55 UTC (rev 5290)
@@ -56,6 +56,7 @@
Opsview::Performanceparsing->init;
use Time::Interval;
use Statistics::Lite qw(min max sum count mean stddev stddevp);
+use Fcntl;
sub usage;
@@ -73,16 +74,33 @@
usage if ( $opts->{h} );
-# Loggers
my $rootdir = "/usr/local/nagios";
my $log4perl = "$rootdir/etc/Log4perl.conf";
+my $pidfile = "$rootdir/var/import_runtime.pid";
Log::Log4perl::init($log4perl);
my $logger = Log::Log4perl->get_logger("import_runtime");
$logger->info("Starting");
-END { $logger->info("Finished") if $logger }
+$SIG{__DIE__} = sub {
+ if ($^S) {
+ # We're in an eval {} and don't want log
+ # this message but catch it later
+ return;
+ }
+ local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
+ $logger->fatal(@_) if $logger;
+ die @_; # Now terminate really
+};
+
+my $remove_pidfile = 1;
+
+END {
+ $logger->info("Finished") if $logger;
+ unlink $pidfile if $remove_pidfile;
+}
+
# database objects
my $runtimedb = Runtime->db_Main;
my $odwdb = Odw->db_Main;
@@ -121,14 +139,45 @@
my $upgrade_lock_file = Opsview::Config->upgrade_lock_file;
if ( -e $upgrade_lock_file ) {
- die "Upgrade seems to still be in progress - check why $upgrade_lock_file still exists\n";
+ $logger->logdie("Upgrade seems to still be in progress - check why $upgrade_lock_file still exists");
}
+# Check for lock file
+# If exists, read pid. If pid does not exist, assume finished and run cleanup. If pid does exist, print message and exit
+my $fh;
+my $c = 0;
+unless ( sysopen( $fh, $pidfile, O_WRONLY | O_EXCL | O_CREAT ) ) {
+ $logger->error("Lock file already exists");
+ if ( open $fh, $pidfile ) {
+ my $pid = <$fh>;
+ $logger->error("Pid file found with pid $pid");
+ if ( kill 0, $pid ) {
+ $logger->error("Process $pid currently running - exiting quietly");
+ $remove_pidfile = 0;
+ exit;
+ }
+ else {
+ $logger->error("Process $pid does not exist - cleaning up");
+ unlink $pidfile;
+ system("/usr/local/nagios/bin/cleanup_import");
+ unless ( sysopen( $fh, $pidfile, O_WRONLY | O_EXCL | O_CREAT ) ) {
+ $logger->logdie("Still cannot get lock after cleanup");
+ }
+ $logger->info("Cleanup successful - continuing");
+ }
+ }
+ else {
+ $logger->logdie("Lock file exists, but cannot read it: $!");
+ }
+}
+print $fh $$;
+close $fh;
+
if ( my ($found) = Odw::Dataload->search( opsview_instance_id => $opsview_instance_id, status => "running" ) ) {
- die "There are running dataloads - exiting\n";
+ $logger->logdie("There are running dataloads - exiting");
}
if ( my ($found) = Odw::Dataload->search( opsview_instance_id => $opsview_instance_id, status => "failed" ) ) {
- die "There are failed dataloads - exiting\n";
+ $logger->logdie("There are failed dataloads - exiting");
}
if ( $opts->{d} ) {
@@ -243,6 +292,11 @@
}
$logger->info("Importing for $start_datetime");
+ my $num_hosts = {};
+ my $num_services = {};
+ my $num_serviceresults = 0;
+ my $num_perfdata = 0;
+
my $dataload = Odw::Dataload->insert(
{ opsview_instance_id => $opsview_instance_id,
period_start_timev => $start_timev,
@@ -272,6 +326,9 @@
my $odw_host = $_->{odw_host_object};
my $odw_servicecheck = $_->{odw_service_object};
+ $num_hosts->{ $odw_host->id } = 1;
+ $num_services->{ $odw_servicecheck->id } = 1;
+
# For every new service object, reset cache
if ( $last_odw_servicecheck_id != $odw_servicecheck->id ) {
if ($last_odw_servicecheck_id) {
@@ -308,8 +365,11 @@
if ($full_odw_import) {
$odwdb->do( "INSERT INTO performance_data (datetime, performance_label, value) VALUES (?, ?, ?)", {}, $service_start_time, $odw_perflabel_id, $p->value );
}
+
+ $num_perfdata++;
}
+ $num_serviceresults++;
}
insert_summarised_perfdata( $start_datetime, $perfdata_cache );
@@ -912,15 +972,22 @@
);
}
+ my $now = time();
+ my $seconds_taken = $now - $dataload->load_start_timev->epoch;
+
# Mark successful dataload
$logger->info("Finished import for hour");
- $dataload->load_end_timev( time() );
+ $dataload->load_end_timev($now);
$dataload->status("success");
+ $dataload->num_hosts( scalar keys %$num_hosts );
+ $dataload->num_services( scalar keys %$num_services );
+ $dataload->num_serviceresults($num_serviceresults);
+ $dataload->num_perfdata($num_perfdata);
+ $dataload->duration($seconds_taken);
$dataload->update;
if ( $opts->{v} ) {
- my $seconds_taken = $dataload->load_end_timev->epoch - $dataload->load_start_timev->epoch;
- my $time_taken = parseInterval(
+ my $time_taken = parseInterval(
seconds => $seconds_taken,
String => 1,
);
Modified: trunk/opsview-core/installer/upgradedb_odw.pl
===================================================================
--- trunk/opsview-core/installer/upgradedb_odw.pl 2010-11-02 20:00:53 UTC (rev 5289)
+++ trunk/opsview-core/installer/upgradedb_odw.pl 2010-11-02 22:04:55 UTC (rev 5290)
@@ -761,6 +761,24 @@
$db->updated;
}
+if ( $db->is_lower('3.9.2') ) {
+ $db->print("Adding extra statistical columns to dataloads table");
+ $dbh->do(
+ "ALTER TABLE dataloads ADD COLUMN num_hosts INT DEFAULT NULL,
+ ADD COLUMN num_services INT DEFAULT NULL,
+ ADD COLUMN num_serviceresults INT DEFAULT NULL,
+ ADD COLUMN num_perfdata INT DEFAULT NULL,
+ ADD COLUMN duration INT DEFAULT NULL"
+ );
+ $db->updated;
+}
+
+if ( $db->is_lower('3.9.3') ) {
+ $db->print("Updating duration column");
+ $dbh->do("UPDATE dataloads SET duration=load_end_timev-load_start_timev");
+ $db->updated;
+}
+
if ( $db_changed || $db->changed ) {
print "Finished updating database", $/;
}
Modified: trunk/opsview-core/lib/Odw/Dataload.pm
===================================================================
--- trunk/opsview-core/lib/Odw/Dataload.pm 2010-11-02 20:00:53 UTC (rev 5289)
+++ trunk/opsview-core/lib/Odw/Dataload.pm 2010-11-02 22:04:55 UTC (rev 5290)
@@ -27,8 +27,13 @@
__PACKAGE__->table("dataloads");
-__PACKAGE__->columns( Primary => qw/id/, );
-__PACKAGE__->columns( Essential => qw/opsview_instance_id period_start_timev period_end_timev load_start_timev load_end_timev status/, );
+__PACKAGE__->columns( Primary => qw/id/, );
+__PACKAGE__->columns(
+ Essential => qw/opsview_instance_id period_start_timev period_end_timev
+ load_start_timev load_end_timev status
+ num_hosts num_services num_serviceresults num_perfdata duration
+ /
+);
__PACKAGE__->has_a(
period_start_timev => 'DateTime',