NagVis / nagvis

Visualization addon for your open source monitoring core
http://nagvis.org/
GNU General Public License v2.0
113 stars 73 forks source link

Problem with regenerating new IDs - corrupted map files (solution attached) #280

Closed longmatys closed 3 years ago

longmatys commented 3 years ago

Hi, I have a lot of maps and objects there. I have used nagvis for some years in version 1.6

I have recently upgraded to 1.9.24 and just when I view maps and do the first refrest I get this error:

Error: (0) in_array() expects parameter 2 to be array, bool given
URL: /nagvis/frontend/nagvis-js/index.php?mod=Map&act=view&show=MAP&header_menu=1
File: /usr/local/nagvis-1.9.24/share/server/core/classes/GlobalMapCfg.php
Line: 1040
#0 [internal function]: nagvisExceptionErrorHandler(2, 'in_array() expe...', '/usr/local/nagv...', 1040, Array)
#1 /usr/local/nagvis-1.9.24/share/server/core/classes/GlobalMapCfg.php(1040): in_array('worldmap', false)
#2 /usr/local/nagvis-1.9.24/share/server/core/classes/GlobalMapCfg.php(497): GlobalMapCfg->checkMapConfigIsValid()
#3 /usr/local/nagvis-1.9.24/share/frontend/nagvis-js/classes/FrontendModMap.php(94): GlobalMapCfg->readMapConfig(true)
#4 /usr/local/nagvis-1.9.24/share/frontend/nagvis-js/classes/FrontendModMap.php(80): FrontendModMap->showViewDialog()
#5 /usr/local/nagvis-1.9.24/share/server/core/functions/index.php(120): FrontendModMap->handleAction()
#6 /usr/local/nagvis-1.9.24/share/frontend/nagvis-js/index.php(53): require('/usr/local/nagv...')
#7 {main}

I dug deep and I find out that this is because I have some bad object_id and your algorithm marked them for new IDs. And there was a problem in function verifyObjectIds:

original code:

private function verifyObjectIds() {
...
    $toBeWritten[$new] = $id;
    $aleadySeen[$new] = true;
...

new code:

private function verifyObjectIds() {
...
    $toBeWritten[$new] = ltrim($id,'_');
    $aleadySeen[$new] = true;
...

The problem is that you are using underscore prefix to mark IDs as invalid and pass them to rewrite new IDs. But you also use underscore to identify that it is not ID, but position of object in file:

public function storeDeleteElement($id, $replaceWith = null) {
...
 if($id[0] === '_')
            list($inObj, $start, $end) = $this->getObjectLinesByNum((int) str_replace('_', '', $id));
        else
            list($inObj, $start, $end) = $this->getObjectLinesById($id);
...

So this case definitely end up as corrupted maps file.

LarsMichelsen commented 3 years ago

Thanks for the detailed report. I just pushed the fix.