Title: [opsview] [10043] Merge of 10029: servicegroup information included in host group status data
Revision
10043
Author
tvoon
Date
2012-09-11 22:44:57 +0100 (Tue, 11 Sep 2012)

Log Message

Merge of 10029: servicegroup information included in host group status data

Modified Paths

Added Paths

Property Changed


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837
   + /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837

Modified: trunk/opsview-core/lib/Runtime/ResultSet/OpsviewHostgroups.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/ResultSet/OpsviewHostgroups.pm	2012-09-11 21:38:46 UTC (rev 10042)
+++ trunk/opsview-core/lib/Runtime/ResultSet/OpsviewHostgroups.pm	2012-09-11 21:44:57 UTC (rev 10043)
@@ -40,7 +40,7 @@
     $args->{totalhgs} = $self->search( {}, { distinct => 1 } )->count;
 
     # Object specific filtering
-    $self = $self->search( { id => $filters->{hostgroupid} } )
+    $self = $self->search( { "me.id" => $filters->{hostgroupid} } )
       if ( exists $filters->{hostgroupid} );
     $self =
       $self->search( { "host_objects.name2" => $filters->{servicecheck} } )
@@ -48,6 +48,10 @@
     $self = $self->search( { "host_objects.hostname" => $filters->{host} } )
       if ( exists $filters->{host} );
 
+    if ( exists $filters->{only_leaves} ) {
+        $self = $self->search( { "lft" => \"=rgt-1" } );
+    }
+
     $self->next::method( $filters, $args );
 }
 
@@ -63,16 +67,34 @@
 sub create_summarized_resultset {
     my ( $self, $downtimes, $filters, $args ) = @_;
 
+    my $joins = "servicestatus";
+    if ( $filters->{include_servicegroups} ) {
+        $joins = [ $joins, { "servicecheck" => "servicegroup" } ];
+    }
     $self = $self->search(
         {},
         {
             join => {
                 hostgroup_hosts =>
-                  [ "hoststatus", { "host_objects" => "servicestatus" } ]
+                  [ "hoststatus", { "host_objects" => $joins } ]
             },
         }
     );
 
+    my $group_by = [
+        "me.id",                       "hostgroup_hosts.host_object_id",
+        "servicestatus.current_state", "service_unhandled"
+    ];
+    if ( $filters->{include_servicegroups} ) {
+        push @$group_by, "servicegroup.id";
+        $self = $self->search(
+            {},
+            {
+                "+select" => [ "servicegroup.name", ],
+                "+as"     => [ "servicegroup_name", ],
+            }
+        );
+    }
     #<<<
     $self = $self->search( {},
         {
@@ -88,16 +110,17 @@
             "host_object_id",
             "total",
             ],
-        group_by => ["me.id", "hostgroup_hosts.host_object_id", "servicestatus.current_state", "service_unhandled"],
+        group_by => $group_by,
         order_by => ["me.name", "me.id", "hostgroup_hosts.host_object_id"],
         }
     );
     #>>>
     if ( $filters->{order} && $filters->{order} eq "dependency" ) {
-        $self =
-          $self->search( {},
-            { order_by => [ "me.lft", "hostgroup_hosts.host_object_id" ] }
-          );
+        my $order_by = [ "me.lft", "hostgroup_hosts.host_object_id" ];
+        if ( $filters->{include_servicegroups} ) {
+            push @$order_by, "servicegroup.id";
+        }
+        $self = $self->search( {}, { order_by => $order_by } );
     }
 
     my $extracols = $filters->{extra_columns};

Modified: trunk/opsview-core/lib/Runtime/ResultSet.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/ResultSet.pm	2012-09-11 21:38:46 UTC (rev 10042)
+++ trunk/opsview-core/lib/Runtime/ResultSet.pm	2012-09-11 21:44:57 UTC (rev 10043)
@@ -233,6 +233,7 @@
             unhandled => 0
         }
     };
+    my $servicegroups_lookup;
     my $inner_sub = sub {
         $status->{name} = $last_group_label;
         $status->{$group_key} = $last_group_key
@@ -353,6 +354,12 @@
             $status->{services}->{$_}->{handled} += $hash->{total};
         }
         $summary->{service}->{$_} += $hash->{total};
+
+        if ( $filters->{include_servicegroups} ) {
+            $status->{servicegroups}->{ $hash->{servicegroup_name} }->{$_}
+              += $hash->{total};
+            $servicegroups_lookup->{ $hash->{servicegroup_name} } = 1;
+        }
         $summary->{service}->{total} += $hash->{total};
     }
 
@@ -373,10 +380,19 @@
     if ( exists $args->{totalhgs} ) {
         $summary->{totalhgs} = $args->{totalhgs};
     }
-    return {
+
+    my $reply = {
         list    => \@list,
         summary => $summary
     };
+
+    if ( $filters->{include_servicegroups} ) {
+        my $servicegroup_list =
+          [ map { { name => $_ } } sort keys %$servicegroups_lookup ];
+        $reply->{servicegroups} = $servicegroup_list;
+    }
+
+    return $reply;
 }
 
 sub max_host_unhandled_state {

Modified: trunk/opsview-core/lib/Runtime/Schema/OpsviewServicechecks.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/Schema/OpsviewServicechecks.pm	2012-09-11 21:38:46 UTC (rev 10042)
+++ trunk/opsview-core/lib/Runtime/Schema/OpsviewServicechecks.pm	2012-09-11 21:44:57 UTC (rev 10043)
@@ -139,7 +139,7 @@
 __PACKAGE__->belongs_to(
     "servicegroup",
     "Runtime::Schema::OpsviewServicegroups",
-    { "foreign.id" => "self.hostgroup_id" },
+    { "foreign.id" => "self.servicegroup_id" },
 );
 
 __PACKAGE__->has_many(

Copied: trunk/opsview-web/t/var/api-status/hostgroup_servicegroup.testcase (from rev 10029, branches/enterprise/DEV-professional/opsview-web/t/var/api-status/hostgroup_servicegroup.testcase)
===================================================================
--- trunk/opsview-web/t/var/api-status/hostgroup_servicegroup.testcase	                        (rev 0)
+++ trunk/opsview-web/t/var/api-status/hostgroup_servicegroup.testcase	2012-09-11 21:44:57 UTC (rev 10043)
@@ -0,0 +1,176 @@
+GET /rest/status/hostgroup?order=dependency&_only_leaves_=1&include_servicegroups=1
+ENDCONTENT
+{
+   "list" : [
+      {
+         "computed_state" : "critical",
+         "downtime" : "2",
+         "hostgroupid" : "4",
+         "hosts" : {
+            "down" : {
+               "handled" : "1",
+               "unhandled" : "1"
+            },
+            "handled" : "7",
+            "total" : "8",
+            "unhandled" : "1",
+            "up" : {
+               "handled" : "6"
+            }
+         },
+         "leaf" : "1",
+         "matpath" : [
+            {
+               "id" : "1",
+               "name" : "Opsview"
+            },
+            {
+               "id" : "3",
+               "name" : "UK"
+            }
+         ],
+         "name" : "Leaf",
+         "servicegroups" : {
+            "Operations" : {
+               "ok" : "1",
+               "unknown" : "18"
+            }
+         },
+         "services" : {
+            "computed_state" : "unknown",
+            "handled" : "4",
+            "ok" : {
+               "handled" : "1"
+            },
+            "total" : "19",
+            "unhandled" : "15",
+            "unknown" : {
+               "handled" : "3",
+               "unhandled" : "15"
+            }
+         }
+      },
+      {
+         "computed_state" : "critical",
+         "downtime" : null,
+         "hostgroupid" : "2",
+         "hosts" : {
+            "handled" : "2",
+            "total" : "2",
+            "unhandled" : "0",
+            "up" : {
+               "handled" : "2"
+            }
+         },
+         "leaf" : "1",
+         "matpath" : [
+            {
+               "id" : "1",
+               "name" : "Opsview"
+            },
+            {
+               "id" : "3",
+               "name" : "UK"
+            }
+         ],
+         "name" : "Monitoring Servers",
+         "servicegroups" : {
+            "Operations" : {
+               "critical" : "1",
+               "ok" : "1"
+            },
+            "Unix" : {
+               "ok" : "1"
+            }
+         },
+         "services" : {
+            "computed_state" : "critical",
+            "critical" : {
+               "unhandled" : "1"
+            },
+            "handled" : "2",
+            "ok" : {
+               "handled" : "2"
+            },
+            "total" : "3",
+            "unhandled" : "1"
+         }
+      },
+      {
+         "computed_state" : "critical",
+         "downtime" : "1",
+         "hostgroupid" : "5",
+         "hosts" : {
+            "handled" : "1",
+            "total" : "1",
+            "unhandled" : "0",
+            "up" : {
+               "handled" : "1"
+            }
+         },
+         "leaf" : "1",
+         "matpath" : [
+            {
+               "id" : "1",
+               "name" : "Opsview"
+            },
+            {
+               "id" : "6",
+               "name" : "UK2"
+            }
+         ],
+         "name" : "Leaf2",
+         "servicegroups" : {
+            "Operations" : {
+               "critical" : "1",
+               "unknown" : "1"
+            },
+            "Unix" : {
+               "unknown" : "1"
+            }
+         },
+         "services" : {
+            "computed_state" : "critical",
+            "critical" : {
+               "unhandled" : "1"
+            },
+            "handled" : "0",
+            "total" : "3",
+            "unhandled" : "3",
+            "unknown" : {
+               "unhandled" : "2"
+            }
+         }
+      }
+   ],
+   "servicegroups" : [
+      {
+         "name" : "Operations"
+      },
+      {
+         "name" : "Unix"
+      }
+   ],
+   "summary" : {
+      "handled" : "16",
+      "host" : {
+         "down" : "2",
+         "handled" : "10",
+         "total" : "11",
+         "unhandled" : "1",
+         "up" : "9"
+      },
+      "service" : {
+         "critical" : "2",
+         "handled" : "6",
+         "ok" : "3",
+         "total" : "25",
+         "unhandled" : "19",
+         "unknown" : "20"
+      },
+      "total" : "36",
+      "totalhgs" : "16",
+      "unhandled" : "20"
+   }
+}
+

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to