Welcome, Guest. Please login or register.

Author Topic: Bugreport: Reports-Serials.php don't delete RRDs,interfaces and modules  (Read 2181 times)


  • Guest
Hello Again!

I've watched that if I delete a old device after it was found by Reports-Serials.php as a new device with an new devicename, Reports-Serials.php don't delete the
- RRD's,
- networks-table-
- vlans-table-
- note-table-
- monitoring-table-
- interface-table- and
- module-table-entries
 belonging to this old one.

By the way: I've watched also that if serial-number is a mac-address in format "xx-xx-xx-xx-xx-xx", Reports-Serials.php don't detect the double existence of the device.

« Last Edit: May 10, 2010, 02:00:18 PM by SteffenS »


  • Guest
FIX: Reports-Serials.php don't delete RRDs,interfaces and modules
« Reply #1 on: July 06, 2011, 08:26:04 AM »
Hello Community,

I've made following changes in Reports-Serials.php:

Change query
Code: [Select]
DbQuery("DELETE FROM devices WHERE name = '".$rmdev."' LIMIT 1", $link);
Code: [Select]
$query = GenQuery('devices','d','','','',array('name'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Device ".DbError($link)."</h4>";}else{echo "<h5>Device $dld $dellbl OK</h5>";}
$query = GenQuery('interfaces','d','','','',array('device'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>IF ".DbError($link)."</h4>";}else{echo "<h5>IF $dld $dellbl OK</h5>";}
$query = GenQuery('modules','d','','','',array('device'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Modules ".DbError($link)."</h4>";}else{echo "<h5>Modules $dld $dellbl OK</h5>";}
$query = GenQuery('links','d','','','',array('device'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Links ".DbError($link)."</h4>";}else{echo "<h5>Links $dld $dellbl OK</h5>";}
$query = GenQuery('links','d','','','',array('neighbour'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Links ".DbError($link)."</h4>";}else{echo "<h5>Links $dld $dellbl OK</h5>";}
$query = GenQuery('configs','d','','','',array('device'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Config ".DbError($link)."</h4>";}else{echo "<h5>Config $dld $dellbl OK</h5>";}
$query = GenQuery('monitoring','d','','','',array('name'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Monitoring ".DbError($link)."</h4>";}else{echo "<h5>Monitoring $dld $dellbl OK</h5>";}
$query = GenQuery('incidents','d','','','',array('name'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Incidents ".DbError($link)."</h4>";}else{echo "<h5>Incidents $dld $dellbl OK</h5>";}
$query = GenQuery('vlans','d','','','',array('device'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Vlans ".DbError($link)."</h4>";}else{echo "<h5>Vlans $dld $dellbl OK</h5>";}
$query = GenQuery('networks','d','','','',array('device'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Networks ".DbError($link)."</h4>";}else{echo "<h5>Networks $dld $dellbl OK</h5>";}
$query = GenQuery('events','d','','','',array('source'),array('='),array($dld) );
if( !@DbQuery($query,$link) ){echo "<h4>Events ".DbError($link)."</h4>";}else{echo "<h5>Events $dld $dellbl OK</h5>";}
$query = GenQuery('devdel','i','','','',array('device','user','time'),'',array($dld,$_SESSION['user'],time()) );
if( !@DbQuery($query,$link) ){echo "<h4>".DbError($link)."</h4>";}else{echo "<h5>$dellbl $dld $updlbl OK</h5>";}
$query = GenQuery('events','i','','','',array('level','time','source','info','type'),'',array('100',time(),$dld,"User $_SESSION[user] deleted this device",'usrd') );
if( !@DbQuery($query,$link) ){echo "<h4>".DbError($link)."</h4>";}else{echo "<h5>$msglbl $updlbl OK</h5>";}

to remove from all tables and import deleted devices in the devdel-table for clean deleting all rrd's at next nedi.pl-run.
(instead of delete device only from devices-table and leave other things from this device behind)
This funktions are copied from Remos Devices-Status.php.

Also I changed query
Code: [Select]
$devices = DbQuery("SELECT name, ip, serial, firstseen, lastseen FROM devices WHERE serial REGEXP BINARY '^[-() A-Z0-9]{2,}$'", $link);
Code: [Select]
$devices = DbQuery("SELECT name, ip, serial, firstseen, lastseen FROM devices WHERE serial NOT REGEXP '^$|^-$|noSuch|err|n/a'", $link);
for devices with MAC-addresses as Serials will be shown now.

If anyone have ideas to optimize, please let me know!
(my main-target was to solve the problem)

Steffen Scholz

for Nedi1.0.5, use
Code: [Select]
if(preg_match("/adm/",$_SESSION['group']) insead of
Code: [Select]
if ($isadmin) and other table-names (see attachment).
« Last Edit: July 06, 2011, 03:23:38 PM by SteffenS »