Send Netdot-devel mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://osl.uoregon.edu/mailman/listinfo/netdot-devel
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Netdot-devel digest..."


Today's Topics:

   1. [SCM] Netdot branch netdot-1.0 updated.
      netdot-1.0.7-12-gbc7307f ([email protected])
   2. [Netdot - Bug #1853] (Resolved) Device inventory  Model/OS
      output not stable ([email protected])


----------------------------------------------------------------------

Message: 1
Date: Mon, 4 May 2015 10:14:22 -0700
From: [email protected]
Subject: [Netdot-devel] [SCM] Netdot branch netdot-1.0 updated.
        netdot-1.0.7-12-gbc7307f
To: [email protected]
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Netdot".

The branch, netdot-1.0 has been updated
       via  bc7307fbdcbd2c55b54866ab5c4db9be9a43d8b7 (commit)
      from  684b354b377615639d3e4085db88402544eacbb7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bc7307fbdcbd2c55b54866ab5c4db9be9a43d8b7
Author: Carlos Vicente <[email protected]>
Date:   Mon May 4 13:13:27 2015 -0400

    Fix incorrect sorting in OS report, optimize code

diff --git a/htdocs/reports/device_inventory.html 
b/htdocs/reports/device_inventory.html
index bdef45e..d4904ef 100644
--- a/htdocs/reports/device_inventory.html
+++ b/htdocs/reports/device_inventory.html
@@ -183,54 +183,68 @@ if ( $report_type eq 'product' || $report_type eq 
'product_monitored' ){
 
 
#######################################################################################
 }elsif ( $report_type eq 'os' ){
-    my %t;
     my @devs = Device->search_by_product_os();
-    foreach my $dev (@devs){
-       my $prod  = ($dev->asset_id && $dev->asset_id->product_id) ? 
-           $dev->asset_id->product_id->id : "Unset";
-       my $manuf = ($dev->asset_id && $dev->asset_id->product_id && 
$dev->asset_id->product_id->manufacturer) ? 
-           $dev->asset_id->product_id->manufacturer->id : 'Unset';
-       my $os    = $dev->os;
+    # Count stuff
+    my %t;
+    my ($manuf, $prod);
+    foreach my $dev ( @devs ){
+       if ( $manuf = $dev->{manuf} ){
+           $t{$manuf}{id} = $dev->{manuf_id};
+       }else{
+           $manuf = 'Unset';
+       }
+       if ( $prod = $dev->{prod} ){
+           $t{$manuf}{product}{$prod}{id} = $dev->{prod_id};
+       }else{
+           $prod = 'Unset';
+       }
+       my $os = $dev->os;
        $t{$manuf}{total}++;
+       $t{$manuf}{product}{$prod}{latest_os} = $dev->{latest_os};
        $t{$manuf}{product}{$prod}{total}++;
-       $t{$manuf}{product}{$prod}{os}{$os}{total}++ if defined ($os);
+       $t{$manuf}{product}{$prod}{os}{$os}{total}++ if defined $os;
     }
 
     @headers = ( 'Manufacturer', 'Model', 'OS', 'Count', );
     my @row = ();
-    foreach my $m ( keys %t ){
+    foreach my $manuf ( sort keys %t ){
        my @row = ();
-       my $entity;
-       if ( $m ne 'Unset' && ($entity = Entity->retrieve($m)) ){
-           push( @row, "<strong><a 
href=\"../generic/view.html?table=Entity&id=$m\">" . $entity->name . 
"</a></strong>" );
+       if ( $manuf ne 'Unset' ){
+           my $str = sprintf('<strong><a 
href="../generic/view.html?table=Entity&id=%d">%s</a></strong>',
+                             $t{$manuf}{id}, $manuf);
+           push(@row, $str);
        }else{
-           push( @row, $m );
+           push(@row, $manuf);
        }
-       push ( @row, " ", " ", "<b>$t{$m}{total}</b>" );
+       push ( @row, " ", " ", "<b>$t{$manuf}{total}</b>" );
        push( @rows, \@row );
-       foreach my $prod ( keys %{$t{$m}{product}} ){
+       foreach my $prod ( sort keys %{$t{$manuf}{product}} ){
            my @row = ();
            push( @row, " " );
-           my $product;
            my $latest_os;
-           if ( $prod ne 'Unset' && ($product = Product->retrieve($prod)) ){
-               push( @row, "<strong><a 
href=\"../generic/view.html?table=Product&id=$prod\">" . $product->name . 
"</a></strong>" );
-               $latest_os = "(recommended: ".$product->latest_os.")" if 
($product->latest_os);
+           if ( $prod ne 'Unset' ){
+               my $str = sprintf('<strong><a 
href="../generic/view.html?table=Product&id=%d">%s</a></strong>',
+                              $t{$manuf}{$prod}{id}, $prod);
+               push( @row, $str );
+               $latest_os = sprintf("(recommended: %s)", 
$t{$manuf}{product}{$prod}{latest_os}) 
+                   if ($t{$manuf}{product}{$prod}{latest_os});
            }else{
                push( @row, $prod );
            }
-           push( @row, $latest_os, $t{$m}{product}{$prod}{total} );
+           push( @row, $latest_os, $t{$manuf}{product}{$prod}{total} );
            push( @rows, \@row );
-           foreach my $os ( keys %{$t{$m}{product}{$prod}{os}} ){
+           foreach my $os ( sort keys %{$t{$manuf}{product}{$prod}{os}} ){
                my @row = ();
                push( @row, " ", " " );
                my $class = " ";
-               if ( $product->latest_os && ($os ne $product->latest_os) ){
+               if ( $latest_os && ($os ne $latest_os) ){
                    $class = 'warn';
                }
-               push( @row, "<a class=\"$class\" 
href=\"../generic/search_obj.html?table=Device&product=$prod&os=$os&res=1\">" . 
-                     $os . '</a>' );
-               push( @row, $t{$m}{product}{$prod}{os}{$os}{total} );
+               my $str = sprintf('<a class="%s" 
href="../generic/search_obj.html?'.
+                                 'table=Device&product=%d&os=%s&res=1">%s</a>',
+                                 $class, $t{$manuf}{product}{$prod}{id}, $os, 
$os);
+               push( @row, $str );
+               push( @row, $t{$manuf}{product}{$prod}{os}{$os}{total} );
                push( @rows, \@row );
            }
        }
diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index 02cf2ba..34c58fd 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -6567,12 +6567,15 @@ __PACKAGE__->set_sql(no_type => qq{
     });
 
 __PACKAGE__->set_sql(by_product_os => qq{
-       SELECT d.id, a.product_id, d.os
-         FROM device d, asset a
-        WHERE d.asset_id = a.id
-          AND d.os is NOT NULL 
-          AND d.os != '0'
-     ORDER BY a.product_id,d.os
+         SELECT  d.id, p.id as prod_id, p.name as prod, p.latest_os as 
latest_os,
+                 m.id as manuf_id, m.name as manuf, d.os as os
+           FROM  device d
+ LEFT OUTER JOIN (asset a, product p, entity m) ON a.id=d.asset_id
+             AND a.product_id=p.id
+             AND m.id=p.manufacturer
+           WHERE d.os is NOT NULL 
+             AND d.os != '0'
+        ORDER BY p.name,d.os
     });
 
 __PACKAGE__->set_sql(for_os_mismatches => qq{

-----------------------------------------------------------------------

Summary of changes:
 htdocs/reports/device_inventory.html | 64 ++++++++++++++++++++++--------------
 lib/Netdot/Model/Device.pm           | 15 +++++----
 2 files changed, 48 insertions(+), 31 deletions(-)


hooks/post-receive
-- 
Netdot


------------------------------

Message: 2
Date: Mon, 4 May 2015 10:15:59 -0700
From: [email protected]
Subject: [Netdot-devel] [Netdot - Bug #1853] (Resolved) Device
        inventory       Model/OS output not stable
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8


Issue #1853 has been updated by Carlos Vicente.

Category set to UserInterface
Status changed from New to Resolved
Assignee set to Carlos Vicente
Resolution set to fixed

Thanks. While fixing the problem, I went ahead and optimized the code to do 
only one DB query.
----------------------------------------
Bug #1853: Device inventory Model/OS output not stable
https://osl.uoregon.edu/redmine/issues/1853#change-3296

Author: Petr ?ech
Status: Resolved
Priority: Low
Assignee: Carlos Vicente
Category: UserInterface
Target version: 1.0.8
Resolution: fixed


Hi,
it seems recent perl hash changes have caused random ordering of Model/OS 
report.

I've made following patch and it seems to be working acceptably.

Regards,
Petr

<pre>
--- device_inventory.html.orig  2015-03-24 09:41:46.143857376 +0100
+++ device_inventory.html       2015-03-24 09:57:32.196742214 +0100
@@ -198,7 +198,7 @@
 
     @headers = ( 'Manufacturer', 'Model', 'OS', 'Count', );
     my @row = ();
-    foreach my $m ( keys %t ){
+    foreach my $m ( sort { Entity->retrieve($a)->name cmp 
Entity->retrieve($b)->name } keys %t ){
        my @row = ();
        my $entity;
        if ( $m ne 'Unset' && ($entity = Entity->retrieve($m)) ){
@@ -208,7 +208,7 @@
        }
        push ( @row, " ", " ", "<b>$t{$m}{total}</b>" );
        push( @rows, \@row );
-       foreach my $prod ( keys %{$t{$m}{product}} ){
+       foreach my $prod ( sort { Product->retrieve($a)->name cmp 
Product->retrieve($b)->name } keys %{$t{$m}{product}} ){
            my @row = ();
            push( @row, " " );
            my $product;
</pre>


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://osl.uoregon.edu/redmine/my/account


------------------------------

_______________________________________________
Netdot-devel mailing list
[email protected]
https://osl.uoregon.edu/mailman/listinfo/netdot-devel


End of Netdot-devel Digest, Vol 98, Issue 3
*******************************************

Reply via email to