Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/CHANGES 2012-09-25 14:11:53 UTC (rev 10160)
@@ -10,6 +10,7 @@
Remove some specified words from device interface ifDescr information to reduce instances of duplicate interface ids being used (level 3 added)
Warnings on multiple hosts using same IP when hosts are configured for MRTG
REST API for /runtime/network can now accept maximum limit of entries returned and provides counts information
+ REST API for /runtime/network can now accept a parent host for topology map
NOTICES:
Removed runtime.opsview_monitoringclusters, which was not used
REST API for /runtime/network result is now wrapped as list element, next to counts information
Modified: trunk/opsview-core/bin/db_runtime
===================================================================
--- trunk/opsview-core/bin/db_runtime 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/bin/db_runtime 2012-09-25 14:11:53 UTC (rev 10160)
@@ -290,6 +290,14 @@
INDEX (child_name)
) ENGINE=InnoDB;
+ CREATE TABLE opsview_hosts_matpaths (
+ id int unsigned NOT NULL auto_increment,
+ object_id INT(10) NOT NULL,
+ matpath TEXT NOT NULL,
+ PRIMARY KEY (id),
+ INDEX (object_id)
+ ) ENGINE=InnoDB;
+
CREATE TABLE opsview_database_version (version varchar(10)) ENGINE=InnoDB;
INSERT opsview_database_version VALUES ('2.8.6');
@@ -315,6 +323,7 @@
INSERT INTO schema_version (major_release, version) VALUES ('3.11', '6');
INSERT INTO schema_version (major_release, version) VALUES ('3.13', '11');
INSERT INTO schema_version (major_release, version) VALUES ('3.15', '9');
+ INSERT INTO schema_version (major_release, version, created_at) VALUES ('20120925hstpths', 'install', NOW());
-- Nagios portion of runtime database
source $topdir/../bin/ndo_mysql.sql;
Modified: trunk/opsview-core/bin/ndoutils_configdumpend
===================================================================
--- trunk/opsview-core/bin/ndoutils_configdumpend 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/bin/ndoutils_configdumpend 2012-09-25 14:11:53 UTC (rev 10160)
@@ -497,6 +497,73 @@
rename_table($table);
+$table = copy_table( 'opsview_hosts_matpaths' );
+{
+
+ my $all_host_ids = $dbh->selectcol_arrayref(
+ q{
+ SELECT id FROM opsview_hosts
+ }
+ );
+
+ my $find_parent_sth = $dbh->prepare_cached(
+ q{
+ SELECT parent_object_id
+ FROM opsview_topology_map
+ WHERE object_id = ?
+ AND child_object_id IS NULL
+ AND parent_object_ID IS NOT NULL
+ GROUP BY parent_object_id
+ }
+ );
+
+ my $set_host_matpath = $dbh->prepare_cached(
+ qq{
+ INSERT INTO $table (object_id, matpath) VALUES(?, ?)
+ }
+ );
+
+ my $find_parent;
+ $find_parent = sub {
+ my $id = shift;
+
+ return unless $id;
+
+ my $parents = $dbh->selectcol_arrayref( $find_parent_sth, {}, $id );
+
+ return @$parents;
+ };
+
+ my $set_host_matpath = sub {
+ my $object_id = shift;
+
+ my $make_tree;
+ $make_tree = sub {
+ my ( $id, @tree ) = @_;
+
+ return unless $id;
+
+ my @parents = $find_parent->($id);
+
+ if (@parents) {
+ for my $parent (@parents) {
+ $make_tree->( $parent, @tree, $id );
+ }
+ }
+ else { # reached root
+ push @tree, $id;
+ my $matpath = join( ',', reverse @tree ) . ",";
+ $set_host_matpath->execute( $object_id, $matpath );
+ }
+ };
+ $make_tree->($object_id);
+ };
+ for my $host_id (@$all_host_ids) {
+ $set_host_matpath->($host_id);
+ }
+}
+rename_table($table);
+
# Clear out downtime that should have finished. Nagios should pass an event
# to the db to say the downtime is complete but some circumstances such as
# db being unavailable can prevent this
Modified: trunk/opsview-core/filelist
===================================================================
--- trunk/opsview-core/filelist 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/filelist 2012-09-25 14:11:53 UTC (rev 10160)
@@ -253,6 +253,7 @@
f nagios:nagios 0644 /usr/local/nagios/lib/Runtime/ResultSet/OpsviewHosts.pm lib/Runtime/ResultSet/OpsviewHosts.pm
f nagios:nagios 0644 /usr/local/nagios/lib/Runtime/ResultSet/OpsviewViewports.pm lib/Runtime/ResultSet/OpsviewViewports.pm
f nagios:nagios 0644 /usr/local/nagios/lib/Runtime/ResultSet/OpsviewTopologyMap.pm lib/Runtime/ResultSet/OpsviewTopologyMap.pm
+f nagios:nagios 0644 /usr/local/nagios/lib/Runtime/ResultSet/OpsviewHostsMatpaths.pm lib/Runtime/ResultSet/OpsviewHostsMatpaths.pm
f nagios:nagios 0644 /usr/local/nagios/lib/Runtime/Schema.pm lib/Runtime/Schema.pm
f nagios:nagios 0644 /usr/local/nagios/lib/Runtime/Schema/NagiosAcknowledgements.pm lib/Runtime/Schema/NagiosAcknowledgements.pm
f nagios:nagios 0644 /usr/local/nagios/lib/Runtime/Schema/NagiosComments.pm lib/Runtime/Schema/NagiosComments.pm
Modified: trunk/opsview-core/installer/upgradedb_runtime.pl
===================================================================
--- trunk/opsview-core/installer/upgradedb_runtime.pl 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/installer/upgradedb_runtime.pl 2012-09-25 14:11:53 UTC (rev 10160)
@@ -1320,6 +1320,23 @@
$db->updated;
}
+unless (
+ $db->is_installed( "20120925hstpths", "Adding hosts matpaths", "all" ) )
+{
+ $dbh->do(
+ qq{
+ CREATE TABLE opsview_hosts_matpaths (
+ id int unsigned NOT NULL auto_increment,
+ object_id INT(10) NOT NULL,
+ matpath TEXT NOT NULL,
+ PRIMARY KEY (id),
+ INDEX (object_id)
+ ) ENGINE=InnoDB;
+ }
+ );
+ $db->updated;
+}
+
if ( $db_changed || $db->changed || $nagios_db->changed ) {
print "Finished updating database", $/;
}
Modified: trunk/opsview-core/lib/Runtime/ResultSet/OpsviewTopologyMap.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/ResultSet/OpsviewTopologyMap.pm 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/lib/Runtime/ResultSet/OpsviewTopologyMap.pm 2012-09-25 14:11:53 UTC (rev 10160)
@@ -45,6 +45,29 @@
$num_filters++;
}
+ # Root host
+ if ( exists $filters->{fromhostname} ) {
+ my $hostnames = convert_to_arrayref( $filters->{fromhostname} );
+ my @matpaths =
+ $self->result_source->schema->resultset("OpsviewHosts")->search(
+ { "me.name" => $hostnames },
+ {
+ result_class => "DBIx::Class::ResultClass::HashRefInflator",
+ join => 'matpaths',
+ select => 'matpaths.matpath',
+ as => 'matpath',
+ }
+ )->all;
+ $self = $self->search(
+ {
+ 'matpaths.matpath' =>
+ { '-like' => [ map { $_->{matpath} . "%" } @matpaths ] }
+ },
+ { join => { host => 'matpaths' } }
+ );
+ $num_filters++;
+ }
+
# Monitoring server
if ( exists $filters->{monitoredby} ) {
$self =
Modified: trunk/opsview-core/lib/Runtime/Schema/OpsviewHosts.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/Schema/OpsviewHosts.pm 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/lib/Runtime/Schema/OpsviewHosts.pm 2012-09-25 14:11:53 UTC (rev 10160)
@@ -183,6 +183,12 @@
{ proxy => [qw/information/] }
);
+__PACKAGE__->has_many(
+ "matpaths",
+ "Runtime::Schema::OpsviewHostsMatpaths",
+ { "foreign.object_id" => "self.id" },
+);
+
__PACKAGE__->resultset_class( "Runtime::ResultSet::OpsviewHosts" );
# Returns an arrayref of errors
Added: trunk/opsview-core/lib/Runtime/Schema/OpsviewHostsMatpaths.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/Schema/OpsviewHostsMatpaths.pm (rev 0)
+++ trunk/opsview-core/lib/Runtime/Schema/OpsviewHostsMatpaths.pm 2012-09-25 14:11:53 UTC (rev 10160)
@@ -0,0 +1,49 @@
+#
+# AUTHORS:
+# Copyright (C) 2003-2012 Opsview Limited. All rights reserved
+#
+# This file is part of Opsview
+#
+#
+package Runtime::Schema::OpsviewHostsMatpaths;
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 NAME
+
+Runtime::Schema::OpsviewHostsMatpaths
+
+=cut
+
+__PACKAGE__->table( "opsview_hosts_matpaths" );
+
+__PACKAGE__->add_columns(
+ "id",
+ {
+ data_type => "integer",
+ is_nullable => 0
+ },
+ "object_id",
+ {
+ data_type => "integer",
+ is_nullable => 0
+ },
+ "matpath",
+ {
+ data_type => "text",
+ is_nullable => 0,
+ size => 64
+ },
+);
+__PACKAGE__->set_primary_key( "id" );
+
+__PACKAGE__->belongs_to(
+ "host",
+ "Runtime::Schema::OpsviewHosts",
+ { "foreign.id" => "self.object_id" },
+);
+
+1;
Modified: trunk/opsview-core/t/var/runtime.test.db
===================================================================
--- trunk/opsview-core/t/var/runtime.test.db 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/t/var/runtime.test.db 2012-09-25 14:11:53 UTC (rev 10160)
@@ -12925,6 +12925,22 @@
UNLOCK TABLES;
+DROP TABLE IF EXISTS `opsview_hosts_matpaths`;
+CREATE TABLE `opsview_hosts_matpaths` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `object_id` int(10) NOT NULL,
+ `matpath` text NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `object_id` (`object_id`)
+) ENGINE=InnoDB;
+
+
+LOCK TABLES `opsview_hosts_matpaths` WRITE;
+/*!40000 ALTER TABLE `opsview_hosts_matpaths` DISABLE KEYS */;
+/*!40000 ALTER TABLE `opsview_hosts_matpaths` ENABLE KEYS */;
+UNLOCK TABLES;
+
+
DROP TABLE IF EXISTS `opsview_monitoringclusternodes`;
CREATE TABLE `opsview_monitoringclusternodes` (
`id` int(11) NOT NULL DEFAULT '0',
@@ -13602,6 +13618,7 @@
INSERT INTO `schema_version` VALUES ('2.11','2',NULL,NULL,NULL);
INSERT INTO `schema_version` VALUES ('2.12','2',NULL,NULL,NULL);
INSERT INTO `schema_version` VALUES ('2.14','3',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('20120925hstpths','all','Adding hosts matpaths','2012-09-25 10:02:56',0);
INSERT INTO `schema_version` VALUES ('3.0','1',NULL,NULL,NULL);
INSERT INTO `schema_version` VALUES ('3.11','6',NULL,NULL,NULL);
INSERT INTO `schema_version` VALUES ('3.13','11',NULL,NULL,NULL);
Modified: trunk/opsview-core/t/var/runtime.topology_test.db
===================================================================
--- trunk/opsview-core/t/var/runtime.topology_test.db 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-core/t/var/runtime.topology_test.db 2012-09-25 14:11:53 UTC (rev 10160)
@@ -5990,7 +5990,41 @@
/*!40000 ALTER TABLE `opsview_hosts` ENABLE KEYS */;
UNLOCK TABLES;
+DROP TABLE IF EXISTS `opsview_hosts_matpaths`;
+CREATE TABLE `opsview_hosts_matpaths` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `object_id` int(10) NOT NULL,
+ `matpath` text NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `object_id` (`object_id`)
+) ENGINE=InnoDB;
+
+LOCK TABLES `opsview_hosts_matpaths` WRITE;
+/*!40000 ALTER TABLE `opsview_hosts_matpaths` DISABLE KEYS */;
+INSERT INTO `opsview_hosts_matpaths` VALUES (1,16,'16,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (2,17,'16,17,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (3,10,'16,10,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (4,15,'16,3,15,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (5,15,'16,5,15,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (6,19,'16,19,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (7,3,'16,3,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (8,4,'16,4,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (9,5,'16,5,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (10,6,'16,3,6,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (11,21,'16,21,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (12,12,'16,12,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (13,7,'16,7,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (14,8,'16,8,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (15,20,'16,20,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (16,9,'16,3,6,9,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (17,18,'16,18,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (18,13,'16,13,');
+INSERT INTO `opsview_hosts_matpaths` VALUES (19,1,'16,1,');
+/*!40000 ALTER TABLE `opsview_hosts_matpaths` ENABLE KEYS */;
+UNLOCK TABLES;
+
+
DROP TABLE IF EXISTS `opsview_monitoringclusternodes`;
CREATE TABLE `opsview_monitoringclusternodes` (
`id` int(11) NOT NULL DEFAULT '0',
@@ -6304,26 +6338,31 @@
DROP TABLE IF EXISTS `schema_version`;
CREATE TABLE `schema_version` (
- `major_release` varchar(16) DEFAULT NULL,
- `version` varchar(16) DEFAULT NULL
+ `major_release` varchar(16) NOT NULL DEFAULT '',
+ `version` varchar(16) DEFAULT NULL,
+ `reason` varchar(255) DEFAULT NULL,
+ `created_at` datetime DEFAULT NULL,
+ `duration` int(11) DEFAULT NULL,
+ PRIMARY KEY (`major_release`)
) ENGINE=InnoDB;
LOCK TABLES `schema_version` WRITE;
/*!40000 ALTER TABLE `schema_version` DISABLE KEYS */;
-INSERT INTO `schema_version` VALUES ('2.10','2');
-INSERT INTO `schema_version` VALUES ('2.11','2');
-INSERT INTO `schema_version` VALUES ('2.12','2');
-INSERT INTO `schema_version` VALUES ('2.14','3');
-INSERT INTO `schema_version` VALUES ('3.0','1');
-INSERT INTO `schema_version` VALUES ('3.3','4');
-INSERT INTO `schema_version` VALUES ('3.5','6');
-INSERT INTO `schema_version` VALUES ('3.6','1');
-INSERT INTO `schema_version` VALUES ('3.7','3');
-INSERT INTO `schema_version` VALUES ('3.9','1');
-INSERT INTO `schema_version` VALUES ('3.11','6');
-INSERT INTO `schema_version` VALUES ('3.13','10');
-INSERT INTO `schema_version` VALUES ('3.15','6');
+INSERT INTO `schema_version` VALUES ('2.10','1',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('2.11','2',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('2.12','2',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('2.14','3',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('20120925hstpths','all','Adding hosts matpaths','2012-09-25 10:02:56',0);
+INSERT INTO `schema_version` VALUES ('3.0','1',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.11','6',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.13','11',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.15','9',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.3','4',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.5','6',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.6','1',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.7','3',NULL,NULL,NULL);
+INSERT INTO `schema_version` VALUES ('3.9','1',NULL,NULL,NULL);
/*!40000 ALTER TABLE `schema_version` ENABLE KEYS */;
UNLOCK TABLES;
Modified: trunk/opsview-web/t/tests/Test/Opsview/Web/REST/Runtime.pm
===================================================================
--- trunk/opsview-web/t/tests/Test/Opsview/Web/REST/Runtime.pm 2012-09-25 12:31:08 UTC (rev 10159)
+++ trunk/opsview-web/t/tests/Test/Opsview/Web/REST/Runtime.pm 2012-09-25 14:11:53 UTC (rev 10160)
@@ -467,6 +467,47 @@
};
+ subtest 'From host name' => sub {
+ plan tests => 2;
+
+ $url = ""
+
+ $expected = {
+ 'rows' => 4,
+ 'total' => '18',
+ 'allrows' => 4,
+ 'list' => [
+ {
+ 'name' => 'monitored_by_slave',
+ 'children' => [],
+ 'parents' => [ 'cisco', 'cisco3' ]
+ },
+ {
+ 'name' => 'cisco',
+ 'children' => [ 'monitored_by_slave', 'cisco4' ],
+ 'parents' => ['opsview']
+ },
+ {
+ 'name' => 'cisco4',
+ 'children' => ['fake_ipv6'],
+ 'parents' => ['cisco']
+ },
+ {
+ 'name' => 'fake_ipv6',
+ 'children' => [],
+ 'parents' => ['cisco4']
+ }
+ ]
+ };
+
+ $mech->get_ok($url);
+ eval { $got = $json->decode( $mech->content ) };
+ die "Bad expected JSON: $@" if $@;
+ cmp_deeply( $got, $expected, "Correct response for $path" )
+ or diag( Data::Dumper->Dump( [$got], ['got'] ) );
+
+ };
+
subtest 'Log in as viewkeywords' => sub {
plan tests => 3;