Modified: trunk/opsview-core/installer/migrate_nagios
===================================================================
--- trunk/opsview-core/installer/migrate_nagios 2012-09-28 00:24:57 UTC (rev 10194)
+++ trunk/opsview-core/installer/migrate_nagios 2012-09-28 07:43:27 UTC (rev 10195)
@@ -12,20 +12,7 @@
#
# This file is part of Opsview
#
-# Opsview is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
#
-# Opsview is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Opsview; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
use strict;
use warnings;
@@ -173,7 +160,7 @@
#### global variables ####
# Initialise debug variable correctly if not already set by --debug
-$options{debug} ||= 2;
+$options{debug} ||= 1;
# Set an arbitrary max level of 8 for debug
$options{debug} = 8 if ( $options{debug} > 8 );
@@ -210,16 +197,22 @@
};
my $notification_methods_to_opsview_mapping = {
- "notify-none" => "",
- "notify-by-epager" => "aql",
- "notify-by-email" => "email",
- "notify-by-atom" => "rss",
- "notify-by-aql" => "aql",
- "host-notify-by-epager" => "aql",
- "host-notify-by-email" => "email",
- "host-notify-by-atom" => "rss",
- "host-notify-by-aql" => "aql",
- "notify-host-by-email" => "email",
+ "notify-none" => "",
+ "notify-by-epager" => "aql",
+ "notify-by-email" => "email",
+ "notify-by-atom" => "rss",
+ "notify-by-aql" => "aql",
+ "host-notify-by-epager" => "aql",
+ "host-notify-by-email" => "email",
+ "host-notify-by-atom" => "rss",
+ "host-notify-by-aql" => "aql",
+ "notify-host-by-email" => "email",
+ "escalate-host-by-email" => "email",
+ "escalate-host-by-pager" => '',
+ 'notify-host-by-mobile' => '',
+ 'notify-host-by-mobile!07810834264' => '',
+ 'notify-host-by-mobile!07775703567' => '',
+ 'notify-host-by-sms' => '',
};
my $command_ignores = {
@@ -233,8 +226,12 @@
"host-notify-by-atom" => 1,
"host-notify-by-aql" => 1,
"ochp_command" => 1,
+ "negate" => 1,
};
+# plugins to be replaced with other plugins
+my $command_replace_with = { "check_custom" => "check_dummy", };
+
#### END VARIABLES ####
#### main ####
@@ -265,7 +262,7 @@
my $timeperiod_objects = {};
TIMEPERIODS: {
- logmsg( 1, "Installing time periods" );
+ logmsg( 2, "Installing time periods" );
foreach my $timeperiod ( @{ $objs->{timeperiod_list} } ) {
my $name = $timeperiod->{timeperiod_name};
logmsg( 2, "- ", $name );
@@ -295,7 +292,7 @@
# populate all contacts, then do groups (which references contact names)
# then add in the groups back to contacts
CONTACTS: {
- logmsg( 1, "Installing contacts (without groups)" );
+ logmsg( 2, "Installing contacts (without groups)" );
foreach my $contact ( @{ $objs->{contact_list} } ) {
my $username = $contact->name;
@@ -369,7 +366,7 @@
my @notificationmethods = ();
foreach my $method (@$host_notification_commands) {
my $setting = $notification_methods_to_opsview_mapping->{$method};
- die "Unrecognised method=$method" unless defined $setting;
+ die "Unrecognised method='$method'" unless defined $setting;
next if $setting eq "";
push @notificationmethods, { name => $setting };
}
@@ -383,7 +380,7 @@
# Create a lookup for a host to a hostgroup, as objects.cache does not lookup in this direction
my $host_to_hostgroup = {};
HOSTGROUPS: {
- logmsg( 1, "Installing hostgroups" );
+ logmsg( 2, "Installing hostgroups" );
my $parent = Opsview::Hostgroup->search( { name => "Opsview", } )->first;
{
@@ -422,7 +419,7 @@
foreach my $h (@$members) {
if ( exists $host_to_hostgroup->{$h} ) {
logmsg(
- 1,
+ 2,
"Host $h already in hostgroup " . $host_to_hostgroup->{$h}
);
}
@@ -442,7 +439,7 @@
# hosts
HOSTS: {
- logmsg( 1, "Installing hosts (without groups)" );
+ logmsg( 2, "Installing hosts (without groups)" );
my $default = Opsview::Hostgroup->search( { name => "Unknown", } )->first;
foreach my $host ( @{ $objs->{host_list} } ) {
@@ -531,32 +528,63 @@
# For Groundwork Opensource, they set their check commands to be like service definitions
# so we need to read all of them in, indexed by command_name, for subsequent creation later
my $check_commands = {};
-logmsg( 1, "Parsing check commands" );
+logmsg( 2, "Parsing check commands" );
COMMANDLIST: {
foreach my $command ( @{ $objs->{command_list} } ) {
+ my $negate = 0;
my $name = $command->command_name;
my $command_line = $command->command_line;
- my ( $dummy, $plugin, $args ) = ( $command_line
- =~ m%(\$USER1\$|/usr/local/nagios/libexec)/(\w+) ?(.*)% );
+ $command_line =~ s#/usr/bin/perl##;
+ # NOTE: plugins may be named directly (i.e. 'snmpget') or contain
+ # full stops or hyphens, or in a rare case '$ARGn$'
+ # Pick up on when negate used and instead flag as 'invert results'
+ my ( $dummy, $plugin, $args );
+ REDO:
+ ( $dummy, $plugin, $args ) = ( $command_line
+ =~ m%(\$USER1\$/|/usr/local/nagios/libexec/)?([\w\.-]+) ?(.*)% );
+
+ if ( $plugin eq 'negate' ) {
+ $command_line =~ s#^.*?/negate\s+##;
+ $negate = 1;
+ goto REDO;
+ }
+
+ if ( $command_replace_with->{$name} ) {
+ logmsg(
+ 1,
+ "WARNING: substituted "
+ . $command_replace_with->{$name}
+ . " for $name"
+ );
+ $plugin = $command_replace_with->{$name};
+ $dummy = 'dummy';
+ }
+
# Some special case ignores
if ( $command_ignores->{$name} ) {
logmsg( 3, "- ignored $name" );
next;
}
- if ( !( $dummy && $plugin ) ) {
- logmsg( 2, "- ignored $name because cannot parse as a plugin" );
- next;
- }
+ if ( $plugin !~ /snmpget/ ) {
+ if ( !( $dummy && $plugin ) ) {
+ logmsg( 2, "- ignored $name because cannot parse as a plugin"
+ );
+ next;
+ }
- if ( $plugin !~ /^check_/ ) {
- logmsg( 1, "- ignored $plugin as it does not start with check_" );
+ if ( $plugin !~ /^check_/ ) {
+ logmsg( 2, "- ignored $plugin as it does not start with check_"
+ );
+ next;
+ }
}
$check_commands->{$name} = {
- plugin => $plugin,
- args => $args
+ plugin => $plugin,
+ args => $args,
+ invertresults => $negate,
};
}
}
@@ -566,7 +594,7 @@
Opsview::Servicegroup->find_or_create( { name => 'IMPORTED' } );
SERVICES: {
- logmsg( 1, "Checking services" );
+ logmsg( 2, "Checking services" );
# drop all into hashes for easier grouping
my %grp_service;
@@ -580,7 +608,7 @@
$service_description =
cleanup_service_description($service_description);
- logmsg( 1, "Service: $hostname: $service_description" );
+ logmsg( 2, "Service: $hostname: $service_description" );
if ( $service->active_checks_enabled == 0 ) {
logmsg( 2, " - ignored due to not being an active check" );
@@ -672,25 +700,35 @@
# Validate all attributes for service check are the same
unless ( $servicecheck->check_period eq $service->check_period ) {
- logmsg( 2, "WARNING - Inconsistent check_period" );
+ logmsg(
+ 1,
+ "WARNING - '$service_description' on '$hostname' Inconsistent check_period"
+ );
}
unless ( $servicecheck->check_interval == $check_interval ) {
- die "Inconsistent check_interval: "
- . $servicecheck->check_interval
- . " versus $check_interval";
+ logmsg(
+ 1,
+ "WARNING - '$service_description' on '$hostname' Inconsistent check_interval: "
+ . $servicecheck->check_interval
+ . " versus $check_interval"
+ );
}
unless (
$servicecheck->check_attempts == $service->max_check_attempts )
{
- die "Inconsistent max_check_attempts: "
- . $servicecheck->check_attempts
- . " versus "
- . $service->max_check_attempts;
+ logmsg( 1,
+ "WARNING - '$service_description' on '$hostname' Inconsistent max_check_attempts: "
+ . $servicecheck->check_attempts
+ . " versus "
+ . $service->max_check_attempts );
}
unless ( $servicecheck->retry_check_interval == $retry_interval ) {
- die "Inconsistent retry_interval: "
- . $servicecheck->retry_check_interval
- . " versus $retry_interval";
+ logmsg(
+ 1,
+ "WARNING - '$service_description' on '$hostname' Inconsistent retry_interval: "
+ . $servicecheck->retry_check_interval
+ . " versus $retry_interval"
+ );
}
my $no_array =
convert_to_arrayref( $service->notification_options );
@@ -704,8 +742,8 @@
my $db_array = convert_to_arrayref( \@_ );
unless ( check_array_ref( $db_array, $no_array ) ) {
logmsg(
- 2,
- "WARNING - Inconsistent notification_options (got "
+ 1,
+ "WARNING - '$service_description' Inconsistent notification_options (got "
. $servicecheck->notification_options
. " but expected "
. join( ",", @$no_array ) . ")"
@@ -750,7 +788,7 @@
}
}
-logmsg( 1, "Finished migration" );
+logmsg( 2, "Finished migration" );
1;
@@ -797,9 +835,14 @@
my $name = shift;
my $newname = $name;
$newname =~ s/:/_/g;
+ $newname =~ s/\+/ and /g;
+ $newname =~ s#\[##g;
+ $newname =~ s#\]##g;
+ $newname = substr( $newname, 0, 63 );
if ( $name ne $newname ) {
- logmsg( 1,
- "WARNING - Changed service description from $name to $newname"
+ logmsg(
+ 1,
+ "WARNING - Changed service description from '$name' to '$newname'"
);
}
return $newname;