Modified: trunk/opsview-core/lib/Runtime/ResultSet/OpsviewHosts.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/ResultSet/OpsviewHosts.pm 2012-09-25 16:12:32 UTC (rev 10169)
+++ trunk/opsview-core/lib/Runtime/ResultSet/OpsviewHosts.pm 2012-09-25 16:13:23 UTC (rev 10170)
@@ -24,6 +24,7 @@
use Opsview::Utils
qw(convert_to_arrayref convert_state_to_text convert_host_state_to_text convert_state_type_to_text);
+use List::MoreUtils qw( uniq );
use base qw/Runtime::ResultSet/;
@@ -55,6 +56,27 @@
$self->search( { 'me.monitored_by' => $filters->{monitoredby}, } );
}
+ # Root host
+ if ( exists $filters->{fromhostname} ) {
+ my $hostnames = convert_to_arrayref( $filters->{fromhostname} );
+ my @matpaths = map { $_->{matpath} . "%" } $self->search(
+ { "me.name" => $hostnames },
+ {
+ result_class => "DBIx::Class::ResultClass::HashRefInflator",
+ join => 'matpaths',
+ select => 'matpaths.matpath',
+ as => 'matpath',
+ }
+ )->all;
+ $self = $self->search(
+ { 'matpaths.matpath' => { '-like' => [ uniq(@matpaths) ] } },
+ {
+ join => 'matpaths',
+ group_by => "me.id",
+ }
+ );
+ }
+
$self->next::method( $filters, $args );
}
@@ -183,7 +205,7 @@
$status->{flapping} = $last_hash->{flapping}
if $last_hash->{flapping}
- or $filters->{includeextradetails};
+ or $filters->{includeextradetails};
$status->{acknowledged} = 1 if $last_hash->{acknowledged};
$status->{comments} = $comments->{ $last_hash->{id} }
Added: trunk/opsview-web/t/var/api-status/host_fromhostname.testcase
===================================================================
--- trunk/opsview-web/t/var/api-status/host_fromhostname.testcase (rev 0)
+++ trunk/opsview-web/t/var/api-status/host_fromhostname.testcase 2012-09-25 16:13:23 UTC (rev 10170)
@@ -0,0 +1,226 @@
+GET /rest/status/host?fromhostname=opsview
+ENDCONTENT
+{
+ "list" : [
+ {
+ "alias" : "cisco",
+ "comments" : "1",
+ "current_check_attempt" : "0",
+ "downtime" : "0",
+ "flapping" : "1",
+ "icon" : "cisco",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "cisco",
+ "num_interfaces" : "1",
+ "num_services" : "3",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "handled" : "0",
+ "total" : "3",
+ "unhandled" : "3",
+ "unknown" : {
+ "unhandled" : "3"
+ }
+ },
+ "unhandled" : "0"
+ },
+ {
+ "alias" : "cisco1",
+ "comments" : "1",
+ "current_check_attempt" : "0",
+ "downtime" : "0",
+ "flapping" : "1",
+ "icon" : "cisco",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "cisco1",
+ "num_interfaces" : "0",
+ "num_services" : "3",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "handled" : "0",
+ "total" : "3",
+ "unhandled" : "3",
+ "unknown" : {
+ "unhandled" : "3"
+ }
+ },
+ "unhandled" : "0"
+ },
+ {
+ "alias" : "cisco2",
+ "current_check_attempt" : "0",
+ "downtime" : "2",
+ "flapping" : "1",
+ "icon" : "cisco",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "cisco2",
+ "num_interfaces" : "0",
+ "num_services" : "3",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "handled" : "0",
+ "total" : "3",
+ "unhandled" : "3",
+ "unknown" : {
+ "unhandled" : "3"
+ }
+ },
+ "unhandled" : "0"
+ },
+ {
+ "alias" : "cisco3",
+ "current_check_attempt" : "0",
+ "downtime" : "2",
+ "icon" : "cisco",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "cisco3",
+ "num_interfaces" : "0",
+ "num_services" : "3",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "handled" : "0",
+ "total" : "3",
+ "unhandled" : "3",
+ "unknown" : {
+ "unhandled" : "3"
+ }
+ },
+ "unhandled" : "0"
+ },
+ {
+ "alias" : "cisco4",
+ "current_check_attempt" : "0",
+ "downtime" : "2",
+ "icon" : "cisco",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "cisco4",
+ "num_interfaces" : "1",
+ "num_services" : "3",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "handled" : "1",
+ "total" : "3",
+ "unhandled" : "2",
+ "unknown" : {
+ "handled" : "1",
+ "unhandled" : "2"
+ }
+ },
+ "unhandled" : "0"
+ },
+ {
+ "alias" : "Host to be monitored by slave",
+ "current_check_attempt" : "0",
+ "downtime" : "1",
+ "flapping" : "1",
+ "icon" : "vmware",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "monitored_by_slave",
+ "num_interfaces" : "0",
+ "num_services" : "5",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "critical" : {
+ "unhandled" : "1"
+ },
+ "handled" : "0",
+ "total" : "3",
+ "unhandled" : "3",
+ "unknown" : {
+ "unhandled" : "2"
+ }
+ },
+ "unhandled" : "0"
+ },
+ {
+ "alias" : "Slave",
+ "current_check_attempt" : "0",
+ "downtime" : "0",
+ "icon" : "opsview",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "opslave",
+ "num_interfaces" : "0",
+ "num_services" : "6",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "critical" : {
+ "unhandled" : "1"
+ },
+ "handled" : "1",
+ "ok" : {
+ "handled" : "1"
+ },
+ "total" : "2",
+ "unhandled" : "1"
+ },
+ "unhandled" : "0"
+ },
+ {
+ "alias" : "Opsview Master Server",
+ "comments" : "1",
+ "current_check_attempt" : "0",
+ "downtime" : "0",
+ "icon" : "opsview",
+ "last_check" : "0",
+ "max_check_attempts" : "0",
+ "name" : "opsview",
+ "num_interfaces" : "0",
+ "num_services" : "6",
+ "output" : "Dummy output",
+ "state" : "up",
+ "state_type" : "soft",
+ "summary" : {
+ "critical" : {
+ "unhandled" : "1"
+ },
+ "handled" : "1",
+ "ok" : {
+ "handled" : "1"
+ },
+ "total" : "2",
+ "unhandled" : "1"
+ },
+ "unhandled" : "0"
+ }
+ ],
+ "summary" : {
+ "handled" : "11",
+ "host" : {
+ "handled" : "8",
+ "total" : "8",
+ "unhandled" : "0",
+ "up" : "8"
+ },
+ "service" : {
+ "critical" : "3",
+ "handled" : "3",
+ "ok" : "2",
+ "total" : "22",
+ "unhandled" : "19",
+ "unknown" : "17"
+ },
+ "total" : "30",
+ "unhandled" : "19"
+ }
+}