Merge lp:~simonsp/ocsinventory-ocsreports/fix_ipdiscover_stale_noninventoried_missing into lp:ocsinventory-ocsreports

Proposed by Paul W. Simons
Status: Merged
Merge reported by: Gonéri Le Bouder
Merged at revision: not available
Proposed branch: lp:~simonsp/ocsinventory-ocsreports/fix_ipdiscover_stale_noninventoried_missing
Merge into: lp:ocsinventory-ocsreports
Diff against target: 108 lines (+33/-24)
2 files modified
plugins/main_sections/ms_ipdiscover/ms_custom_info.php (+5/-2)
plugins/main_sections/ms_ipdiscover/ms_ipdiscover.php (+28/-22)
To merge this branch: bzr merge lp:~simonsp/ocsinventory-ocsreports/fix_ipdiscover_stale_noninventoried_missing
To post a comment you must log in.
Revision history for this message
Paul W. Simons (simonsp) wrote :

This fixes a problem where an update network map would not be used over a stale inventory. If a pc was inventoried on subnet A, and then moved to subnet B, when displaying the results of devices on subnet B, it would not show up. I have modified sql statements to force the stale inventory to show up as a non-inventoried machine, since the inventory needs to be updated.

Revision history for this message
Gonéri Le Bouder (goneri) wrote :

Thank you! :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/main_sections/ms_ipdiscover/ms_custom_info.php'
2--- plugins/main_sections/ms_ipdiscover/ms_custom_info.php 2009-11-13 10:57:00 +0000
3+++ plugins/main_sections/ms_ipdiscover/ms_custom_info.php 2010-01-26 15:35:21 +0000
4@@ -125,8 +125,11 @@
5 //$netid=mysql_escape_string($protectedGet['value']);
6 if ($protectedGet['prov'] == "no_inv"){
7 $title=$l->g(947);
8- $sql="SELECT ip, mac, mask, date, name FROM netmap WHERE netid='".$protectedGet['value']."' AND mac NOT IN (SELECT DISTINCT(macaddr) FROM networks)
9- AND mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)";
10+ $sql="SELECT ip, mac, mask, date, name FROM netmap n
11+ LEFT JOIN networks ns ON ns.macaddr=n.mac
12+ WHERE n.netid='".$protectedGet['value']."'
13+ AND (ns.macaddr IS NULL OR ns.IPSUBNET <> n.netid)
14+ AND mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)";
15 $list_fields= array($l->g(34) => 'ip','MAC'=>'mac',
16 $l->g(208)=>'mask',
17 $l->g(232)=>'date',
18
19=== modified file 'plugins/main_sections/ms_ipdiscover/ms_ipdiscover.php'
20--- plugins/main_sections/ms_ipdiscover/ms_ipdiscover.php 2009-11-16 17:51:40 +0000
21+++ plugins/main_sections/ms_ipdiscover/ms_ipdiscover.php 2010-01-26 15:35:21 +0000
22@@ -63,11 +63,12 @@
23 GROUP BY netid)
24 ident on ipdiscover.RSX=ident.RSX left join
25 (SELECT COUNT(DISTINCT mac) as c,'NON IDENTIFIE' as TYPE,netid as RSX
26- FROM netmap
27- WHERE mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
28- and mac NOT IN (SELECT DISTINCT(macaddr) FROM networks)
29- and netid in ('".$list_rsx."')
30- GROUP BY netid)
31+ FROM netmap n
32+ LEFT JOIN networks ns ON ns.macaddr=n.mac
33+ WHERE n.mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
34+ and (ns.macaddr IS NULL OR ns.IPSUBNET <> n.netid)
35+ and n.netid in ('".$list_rsx."')
36+ GROUP BY n.netid)
37 non_ident on non_ident.RSX=ipdiscover.RSX where non_ident.c is not null and ident.c is not null
38 union
39 select inv.RSX,
40@@ -93,11 +94,12 @@
41 GROUP BY netid)
42 ident on ipdiscover.RSX=ident.RSX left join
43 (SELECT COUNT(DISTINCT mac) as c,'NON IDENTIFIE' as TYPE,netid as RSX
44- FROM netmap
45- WHERE mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
46- and mac NOT IN (SELECT DISTINCT(macaddr) FROM networks)
47- and netid in ('".$list_rsx."')
48- GROUP BY netid)
49+ FROM netmap n
50+ LEFT JOIN networks ns ON ns.macaddr=n.mac
51+ WHERE n.mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
52+ and (ns.macaddr IS NULL OR ns.IPSUBNET <> n.netid)
53+ and n.netid in ('".$list_rsx."')
54+ GROUP BY n.netid)
55 non_ident on non_ident.RSX=ipdiscover.RSX where non_ident.c is null and ident.c is not null
56 union
57 select inv.RSX,
58@@ -123,11 +125,12 @@
59 GROUP BY netid)
60 ident on ipdiscover.RSX=ident.RSX left join
61 (SELECT COUNT(DISTINCT mac) as c,'NON IDENTIFIE' as TYPE,netid as RSX
62- FROM netmap
63- WHERE mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
64- and mac NOT IN (SELECT DISTINCT(macaddr) FROM networks)
65- and netid in ('".$list_rsx."')
66- GROUP BY netid)
67+ FROM netmap n
68+ LEFT JOIN networks ns ON ns.macaddr=n.mac
69+ WHERE n.mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
70+ and (ns.macaddr IS NULL OR ns.IPSUBNET <> n.netid)
71+ and n.netid in ('".$list_rsx."')
72+ GROUP BY n.netid)
73 non_ident on non_ident.RSX=ipdiscover.RSX where ident.c is null and non_ident.c is not null
74 union
75 select inv.RSX,
76@@ -153,11 +156,12 @@
77 GROUP BY netid)
78 ident on ipdiscover.RSX=ident.RSX left join
79 (SELECT COUNT(DISTINCT mac) as c,'NON IDENTIFIE' as TYPE,netid as RSX
80- FROM netmap
81- WHERE mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
82- and mac NOT IN (SELECT DISTINCT(macaddr) FROM networks)
83- and netid in ('".$list_rsx."')
84- GROUP BY netid)
85+ FROM netmap n
86+ LEFT JOIN networks ns ON ns.macaddr=n.mac
87+ WHERE n.mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
88+ and (ns.macaddr IS NULL OR ns.IPSUBNET <> n.netid)
89+ and n.netid in ('".$list_rsx."')
90+ GROUP BY n.netid)
91 non_ident on non_ident.RSX=ipdiscover.RSX where ident.c is null and non_ident.c is null
92 ) toto";
93
94@@ -199,10 +203,12 @@
95 $tab_options['NO_TRI']['LBL_RSX']='LBL_RSX';
96
97 $sql_count="SELECT COUNT(DISTINCT mac) as total
98- FROM netmap
99+ FROM netmap n
100+ LEFT OUTER JOIN networks ns ON ns.macaddr = mac
101 WHERE mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)
102- and mac NOT IN (SELECT DISTINCT(macaddr) FROM networks)
103+ and ( ns.macaddr IS NULL OR ns.IPSUBNET <> n.netid)
104 and netid in ('".$list_rsx."')";
105+
106 $res_count = mysql_query($sql_count, $_SESSION['OCS']["readServer"] );
107 $val_count = mysql_fetch_array( $res_count );
108 $strEnTete = $_SESSION['OCS']["ipdiscover_id"]." ".$dpt[$protectedPost['DPT_CHOISE']]." <br>";

Subscribers

People subscribed via source and target branches