Title: [opsview] [10474] Search box in the main interface now also searches host descriptions
Revision
10474
Author
dferguson
Date
2012-10-16 15:53:35 +0100 (Tue, 16 Oct 2012)

Log Message

Search box in the main interface now also searches host descriptions

OPS-1863

Modified Paths

Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES	2012-10-16 14:52:29 UTC (rev 10473)
+++ trunk/CHANGES	2012-10-16 14:53:35 UTC (rev 10474)
@@ -6,6 +6,7 @@
     Attributes are now allowed to use numbers in the name
     Added enhanced monitoring for Oracle/PostgreSQL (new service checks to existing Host template), Microsoft SQL, Windows Server 2008 via WMI (Base/DNS/Exchange/IIS Terminal Services)
     /rest/runtime/network?fromhostname=host now returns list back roughly based on depth of host
+    Search box in the main interface now also searches host descriptions
     NOTICES:
     FIXES:
     Fixed apache configuration for redundancy, specifically removing apache_proxy_ssl.conf and replacing with apache_ssl.conf

Modified: trunk/opsview-core/lib/Runtime/Searches.pm
===================================================================
--- trunk/opsview-core/lib/Runtime/Searches.pm	2012-10-16 14:52:29 UTC (rev 10473)
+++ trunk/opsview-core/lib/Runtime/Searches.pm	2012-10-16 14:53:35 UTC (rev 10474)
@@ -723,7 +723,7 @@
             map {
                 $flag = 1 if exists $add_select{$_};
                 exists $valid_orderbys{$_} ? $valid_orderbys{$_} : ()
-              } @$_
+            } @$_
         ];
         if ($flag) {
 
@@ -1412,7 +1412,7 @@
         foreach my $host ( @{ $service->{hosts} } ) {
             $summary->{ $host->{state} }++;
             $summary->{ ( $host->{unhandled} == 1 ? "unhandled" : "handled" )
-              }++;
+            }++;
             $summary->{total}++;
             $summary->{metrics} += scalar @{ $host->{metrics} }
               if exists $host->{metrics};
@@ -1463,8 +1463,9 @@
     my $tables = ["opsview_hosts"];
     my $where  = {
         -or => [
-            "opsview_hosts.name" => "%" . $params->{q} . "%",
-            "opsview_hosts.ip"   => "%" . $params->{q} . "%"
+            "opsview_hosts.name"  => "%" . $params->{q} . "%",
+            "opsview_hosts.ip"    => "%" . $params->{q} . "%",
+            "opsview_hosts.alias" => "%" . $params->{q} . "%",
         ],
     };
     if ( $contact->can_view_all ) {
@@ -1482,6 +1483,7 @@
             "DISTINCT(opsview_hosts.name) as name",
             "opsview_hosts.icon_filename as icon",
             "opsview_hosts.ip as ip",
+            "opsview_hosts.alias as alias",
         ],
         $where,
         ["name"],
@@ -1493,9 +1495,10 @@
     while ( @_ = $sth->fetchrow_array ) {
         push @$list,
           {
-            name => $_[0],
-            icon => $_[1],
-            ip   => $_[2]
+            name  => $_[0],
+            icon  => $_[1],
+            ip    => $_[2],
+            alias => $_[3],
           };
     }
     return $list;

Modified: trunk/opsview-core/t/803searches.t
===================================================================
--- trunk/opsview-core/t/803searches.t	2012-10-16 14:52:29 UTC (rev 10473)
+++ trunk/opsview-core/t/803searches.t	2012-10-16 14:53:35 UTC (rev 10474)
@@ -30,94 +30,113 @@
 
 $expected = [
     {
-        icon => "cisco",
-        ip   => "192.168.10.20",
-        name => "cisco"
+        icon  => "cisco",
+        ip    => "192.168.10.20",
+        name  => "cisco",
+        alias => 'cisco',
     },
     {
-        icon => "cisco",
-        ip   => "192.168.10.23",
-        name => "cisco1"
+        icon  => "cisco",
+        ip    => "192.168.10.23",
+        name  => "cisco1",
+        alias => 'cisco1',
     },
     {
-        icon => "cisco",
-        ip   => "192.168.10.22",
-        name => "cisco2"
+        icon  => "cisco",
+        ip    => "192.168.10.22",
+        name  => "cisco2",
+        alias => 'cisco2',
     },
     {
-        icon => "cisco",
-        ip   => "192.168.10.22",
-        name => "cisco3"
+        icon  => "cisco",
+        ip    => "192.168.10.22",
+        name  => "cisco3",
+        alias => 'cisco3',
     },
     {
-        icon => "cisco",
-        ip   => "not_a_real_host",
-        name => "cisco4"
+        icon  => "cisco",
+        ip    => "not_a_real_host",
+        name  => "cisco4",
+        alias => 'cisco4',
     },
     {
-        icon => "",
-        ip   => "",
-        name => "cloned"
+        icon  => "",
+        ip    => "",
+        name  => "cloned",
+        alias => 'cloned',
     },
     {
-        icon => "dragonflybsd",
-        ip   => "",
-        name => "cloned2"
+        icon  => "dragonflybsd",
+        ip    => "",
+        name  => "cloned2",
+        alias => 'cloned2',
     },
     {
-        icon => "debian",
-        ip   => "192.168.50.10",
-        name => "doesnt_exist_1"
+        icon  => "debian",
+        ip    => "192.168.50.10",
+        name  => "doesnt_exist_1",
+        alias => 'doesnt_exist_1',
     },
     {
-        icon => "debian",
-        ip   => "192.168.50.11",
-        name => "doesnt_exist_2"
+        icon  => "debian",
+        ip    => "192.168.50.11",
+        name  => "doesnt_exist_2",
+        alias => 'doesnt_exist_2',
     },
     {
-        icon => "dragonflybsd",
-        ip   => "hostname1",
-        name => "host_locally_monitored"
+        icon  => "dragonflybsd",
+        ip    => "hostname1",
+        name  => "host_locally_monitored",
+        alias => 'host_locally_monitored',
     },
     {
-        icon => "debian",
-        ip   => "not_in_opsview_db",
-        name => "missing_from_configuration"
+        icon  => "debian",
+        ip    => "not_in_opsview_db",
+        name  => "missing_from_configuration",
+        alias => 'missing_from_configuration',
     },
     {
-        icon => "wireless",
-        ip   => "monitored_by_clusterip",
-        name => "monitored_by_cluster"
+        icon  => "wireless",
+        ip    => "monitored_by_clusterip",
+        name  => "monitored_by_cluster",
+        alias => 'Host to be monitored by slave',
     },
     {
-        icon => "vmware",
-        ip   => "monitored_by_slave",
-        name => "monitored_by_slave"
+        icon  => "vmware",
+        ip    => "monitored_by_slave",
+        name  => "monitored_by_slave",
+        alias => 'Host to be monitored by slave',
     },
     {
-        icon => "opsview",
-        ip   => "opslave",
-        name => "opslave"
+        icon  => "opsview",
+        ip    => "opslave",
+        name  => "opslave",
+        alias => 'Slave',
     },
     {
-        icon => "opsview",
-        ip   => "localhost",
-        name => "opsview"
+        icon  => "opsview",
+        ip    => "localhost",
+        name  => "opsview",
+        alias => 'Opsview Master Server',
     },
     {
-        icon => "wireless",
-        ip   => "opsviewdev1.der.altinity",
-        name => "opsviewdev1"
+        icon  => "wireless",
+        ip    => "opsviewdev1.der.altinity",
+        name  => "opsviewdev1",
+        alias => '',
     },
     {
-        icon => "vpn",
-        ip   => "192.168.101.46",
-        name => "opsviewdev46"
+        icon  => "vpn",
+        ip    => "192.168.101.46",
+        name  => "opsviewdev46",
+        alias => '',
     },
     {
         icon => "vmware",
         ip   => "resolved_services",
-        name => "resolved_services"
+        name => "resolved_services",
+        alias =>
+          'Host with services based on templates, exceptions and timed exce',
     },
 ];
 
@@ -131,69 +150,83 @@
 # no services on that host, so it is effectively missing
 $expected = [
     {
-        icon => "cisco",
-        ip   => "192.168.10.20",
-        name => "cisco"
+        icon  => "cisco",
+        ip    => "192.168.10.20",
+        name  => "cisco",
+        alias => 'cisco',
     },
     {
-        icon => "cisco",
-        ip   => "192.168.10.23",
-        name => "cisco1"
+        icon  => "cisco",
+        ip    => "192.168.10.23",
+        name  => "cisco1",
+        alias => 'cisco1',
     },
     {
-        icon => "cisco",
-        ip   => "192.168.10.22",
-        name => "cisco2"
+        icon  => "cisco",
+        ip    => "192.168.10.22",
+        name  => "cisco2",
+        alias => 'cisco2',
     },
     {
-        icon => "cisco",
-        ip   => "192.168.10.22",
-        name => "cisco3"
+        icon  => "cisco",
+        ip    => "192.168.10.22",
+        name  => "cisco3",
+        alias => 'cisco3',
     },
     {
-        icon => "cisco",
-        ip   => "not_a_real_host",
-        name => "cisco4"
+        icon  => "cisco",
+        ip    => "not_a_real_host",
+        name  => "cisco4",
+        alias => 'cisco4',
     },
     {
-        icon => "dragonflybsd",
-        ip   => "",
-        name => "cloned2"
+        icon  => "dragonflybsd",
+        ip    => "",
+        name  => "cloned2",
+        alias => 'cloned2',
     },
     {
-        icon => "debian",
-        ip   => "192.168.50.10",
-        name => "doesnt_exist_1"
+        icon  => "debian",
+        ip    => "192.168.50.10",
+        name  => "doesnt_exist_1",
+        alias => 'doesnt_exist_1',
     },
     {
-        icon => "debian",
-        ip   => "192.168.50.11",
-        name => "doesnt_exist_2"
+        icon  => "debian",
+        ip    => "192.168.50.11",
+        name  => "doesnt_exist_2",
+        alias => 'doesnt_exist_2',
     },
     {
-        icon => "dragonflybsd",
-        ip   => "hostname1",
-        name => "host_locally_monitored"
+        icon  => "dragonflybsd",
+        ip    => "hostname1",
+        name  => "host_locally_monitored",
+        alias => 'host_locally_monitored',
     },
     {
-        icon => "vmware",
-        ip   => "monitored_by_slave",
-        name => "monitored_by_slave"
+        icon  => "vmware",
+        ip    => "monitored_by_slave",
+        name  => "monitored_by_slave",
+        alias => 'Host to be monitored by slave',
     },
     {
-        icon => "opsview",
-        ip   => "opslave",
-        name => "opslave"
+        icon  => "opsview",
+        ip    => "opslave",
+        name  => "opslave",
+        alias => 'Slave',
     },
     {
-        icon => "opsview",
-        ip   => "localhost",
-        name => "opsview"
+        icon  => "opsview",
+        ip    => "localhost",
+        name  => "opsview",
+        alias => 'Opsview Master Server',
     },
     {
         icon => "vmware",
         ip   => "resolved_services",
-        name => "resolved_services"
+        name => "resolved_services",
+        alias =>
+          'Host with services based on templates, exceptions and timed exce',
     },
 ];
 
@@ -206,9 +239,10 @@
 
 $expected = [
     {
-        name => "monitored_by_slave",
-        icon => "vmware",
-        ip   => "monitored_by_slave",
+        name  => "monitored_by_slave",
+        icon  => "vmware",
+        ip    => "monitored_by_slave",
+        alias => 'Host to be monitored by slave',
     },
 ];
 

Modified: trunk/opsview-web/lib/Opsview/Web/Controller/Search.pm
===================================================================
--- trunk/opsview-web/lib/Opsview/Web/Controller/Search.pm	2012-10-16 14:52:29 UTC (rev 10473)
+++ trunk/opsview-web/lib/Opsview/Web/Controller/Search.pm	2012-10-16 14:53:35 UTC (rev 10474)
@@ -79,6 +79,11 @@
           Runtime::Searches->list_hosts_by_contact( $c->user, $c->req->params );
         foreach my $host (@$hostlist_ref) {
             my $hash = { name => $host->{name} };
+            if ( $host->{alias} ) {
+
+                # Alias here is used for host description
+                $hash->{desc} = $host->{alias};
+            }
             if ( $host->{ip} ) {
                 $hash->{alias} = $host->{ip};
             }
@@ -118,8 +123,8 @@
     $c->stash( wrapper => "wrappers/blank" );
 }
 
-sub service : Local : Does(ACL) : AllowedRole(VIEWSOME) : AllowedRole(VIEWALL) :
-  ACLDetachTo(/access_denied) {
+sub service : Local : Does(ACL) : AllowedRole(VIEWSOME) : AllowedRole(VIEWALL)
+  : ACLDetachTo(/access_denied) {
     my ( $self, $c ) = @_;
 
     $c->stash( wrapper => "wrappers/blank" );

Modified: trunk/opsview-web/root/search/host
===================================================================
--- trunk/opsview-web/root/search/host	2012-10-16 14:52:29 UTC (rev 10473)
+++ trunk/opsview-web/root/search/host	2012-10-16 14:53:35 UTC (rev 10474)
@@ -11,7 +11,7 @@
 item.name;
 
 IF item.alias && item.alias != item.name;
-  %]<span class="informal"> ([% item.alias %])</span>[%
+  %]<span class="informal"> ([% item.alias %][% IF item.desc %] : [% item.desc ; END %])</span>[%
 END;
 
 -%]

Modified: trunk/opsview-web/t/822sidebar_search.t
===================================================================
--- trunk/opsview-web/t/822sidebar_search.t	2012-10-16 14:52:29 UTC (rev 10473)
+++ trunk/opsview-web/t/822sidebar_search.t	2012-10-16 14:53:35 UTC (rev 10474)
@@ -35,11 +35,11 @@
 $mech->get_ok( 'http://localhost/search/host?q=cis' );
 my $expected = '
 <ul>
-<li>cisco<span class="informal"> (192.168.10.20)</span></li>
-<li>cisco1<span class="informal"> (192.168.10.23)</span></li>
-<li>cisco2<span class="informal"> (192.168.10.22)</span></li>
-<li>cisco3<span class="informal"> (192.168.10.22)</span></li>
-<li>cisco4<span class="informal"> (not_a_real_host)</span></li>
+<li>cisco<span class="informal"> (192.168.10.20:cisco)</span></li>
+<li>cisco1<span class="informal"> (192.168.10.23:cisco1)</span></li>
+<li>cisco2<span class="informal"> (192.168.10.22:cisco2)</span></li>
+<li>cisco3<span class="informal"> (192.168.10.22:cisco3)</span></li>
+<li>cisco4<span class="informal"> (not_a_real_host:cisco4)</span></li>
 </ul>
 ';
 is_string_nows( $mech->content, $expected, 'search results ok' );
@@ -48,8 +48,8 @@
 # This test ensures the whitespace is as expected
 $mech->get_ok( 'http://localhost/search/host?q=opsview' );
 $expected = '<ul>
-<li>missing_from_configuration<span class="informal"> (not_in_opsview_db)</span></li>
-<li>opsview<span class="informal"> (localhost)</span></li>
+<li>missing_from_configuration<span class="informal"> (not_in_opsview_db : missing_from_configuration)</span></li>
+<li>opsview<span class="informal"> (localhost : Opsview Master Server)</span></li>
 <li>opsviewdev1<span class="informal"> (opsviewdev1.der.altinity)</span></li>
 <li>opsviewdev46<span class="informal"> (192.168.101.46)</span></li>
 <li>hg Opsview</li>

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

Reply via email to