howardjones / network-weathermap

Network Weathermap draws diagrams from data
http://www.network-weathermap.com/
MIT License
426 stars 95 forks source link

INNOTES/OUTNOTES Issue #153

Closed jpobeda closed 5 years ago

jpobeda commented 5 years ago

Hi Howie, it's been a long time =^D

Before we start, I'm running Cacti 1.1.37 and network weathermap 0.98dev version reworked to work on 1.x (I can't even remember how/where did I get it from).

So I understand I'm out of support

I set this link

chrome_2018-09-10_10-18-52

As you see, it's all static and pretty basic. The gif below shows you that I get OUTNOTES for IN and OUT sides of the link.

2018-09-10_10-18-37

Then I tried the following config (getting rid of the OUTNOTES statement)

chrome_2018-09-10_10-15-18

And this gif shows you what do I get

2018-09-10_10-15-03

Defaults on this map are

# TEMPLATE-only LINKs:
LINK DEFAULT
    WIDTH 4
    ARROWSTYLE compact
    BWFONT 208
    BWOUTLINECOLOR 0 102 153
    OUTLINECOLOR none
    BWFONTCOLOR 0 102 153
    USESCALE LINKS percent
    BWLABEL bits
    BANDWIDTH 100M

I don't have access to cacti 0.8.x anymore, are you able to confirm if this is working fine or if it's something that might have come out from running it with cacti 1.x ?

btw, nothing on the logs indicating errors/warnings I guess I could run it in debug mode and see if spot anything unusual when handling the notes.

Thanks

howardjones commented 5 years ago

Just to give me a little bit of a clue for the version... in lib/ is there a Weathermap directory, or Weathermap.class.php? How many files are in there?

howardjones commented 5 years ago

Also, if you edit this file using the editor, it doesn't move around the notes (from in to out, or from in/out to a single notes item)? That would indicate an issue with ReadConfig(). It sounds like that is OK.

jpobeda commented 5 years ago
 # ls /usr/share/cacti1x/plugins/weathermap/lib/
all.php                    image-functions.php               WeatherMapUIBase.class.php
base-classes.php           index.php                         WMAngledLinkGeometry.class.php
cacti10-plugin-hooks.php   plugin-base-classes.php           WMBoundingBox.class.php
cacti88-plugin-common.php  poller-common.php                 WMColour.class.php
cacti88-plugin-hooks.php   post                              WMCurvedLinkGeometry.class.php
cacti88-plugin-mgmt.php    pre                               WMDebug.php
cacti88-plugin-user.php    SimpleTemplate.class.php          WMImageLoader.class.php
cacti-pick.php             Weathermap.class.php              WMImageUtility.php
cacti-plugin-poller.php    WeatherMapConfigReader.class.php  WMLine.class.php
CatmullRom.class.php       WeatherMapDataItem.class.php      WMLinkGeometry.class.php
constants.php              WeatherMapEditor.class.php        WMLinkGeometryFactory.class.php
database.php               WeatherMapEditorUI.class.php      WMPoint.class.php
datasources                WeatherMap.functions.php          WMRectangle.class.php
ds-common.php              WeatherMapLink.class.php          WMSpine.class.php
editor.inc.php             WeathermapManager.class.php       WMStats.php
exceptions.php             WeatherMapNode.class.php          WMTarget.class.php
fonts.php                  WeatherMapPoller.class.php        WMUtility.class.php
geometry.php               WeatherMapRuntime.class.php       WMVector.class.php
globals.php                WeatherMapScale.class.php
HTMLImagemap.class.php     WeatherMapTextItem.class.php
ls /usr/share/cacti1x/plugins/weathermap/lib/ | wc -l
58

There is a Weathermap.class.php

It understood well, you looking to see if using web editor replaces IN with OUT or vice versa, right?

2018-09-10_12-01-47

Should I run this on debug mode and see what readconfig is reading?

howardjones commented 5 years ago

No, just pressing submit, or editing anything in the map is a good enough test. It reads the whole config a rewrites it every time you make a change. OK, so now you know that the problem is in the drawing/html code. That's in the Weathermap.class.php - search for overlib to find the HTML output function.

jpobeda commented 5 years ago

Am I on the right place?

public function calculateImagemap()
    {
        wm_debug("Trace: calculateImagemap()\n");

        // loop through everything. Figure out along the way if it's a node or a link
        $allItems = $this->buildAllItemsList();

        foreach ($allItems as $mapItem) {
            $type = $mapItem->my_type();
            # $prefix = substr($type, 0, 1);

            $dirs = array();
            if ($type == 'LINK') {
                $dirs = array(IN => array(0, 2), OUT => array(1, 3));
            }
            if ($type == 'NODE') {
                $dirs = array(IN => array(0, 1, 2, 3));
            }
// check to see if any of the relevant things have a value
            $change = "";
            foreach ($dirs as $d => $parts) {
                $change .= join('', $mapItem->overliburl[$d]);
                $change .= $mapItem->notestext[$d];
            }
            // skip all this if it's a template node
            if ($mapItem->isTemplate()) {
                $change = "";
            }

            if ($this->htmlstyle == "overlib") {
                if ($change != '') {
                    // find the middle of the map
                    $center_x = $this->width / 2;
                    $center_y = $this->height / 2;

                    $type = $mapItem->my_type();

                    if ($type == 'NODE') {
                        $mid_x = $mapItem->x;
                        $mid_y = $mapItem->y;
                    }
                    if ($type == 'LINK') {
                        $a_x = $this->nodes[$mapItem->a->name]->x;
                        $a_y = $this->nodes[$mapItem->a->name]->y;

                        $b_x = $this->nodes[$mapItem->b->name]->x;
                        $b_y = $this->nodes[$mapItem->b->name]->y;

                        $mid_x = ($a_x + $b_x) / 2;
                        $mid_y = ($a_y + $b_y) / 2;
                    }
                    $left = "";
                    $above = "";
                    $img_extra = "";

                    if ($mapItem->overlibwidth != 0) {
                        $left = "WIDTH," . $mapItem->overlibwidth . ",";
                        $img_extra .= " WIDTH=$mapItem->overlibwidth";

                        if ($mid_x > $center_x) {
                            $left .= "LEFT,";
                        }
                    }

                    if ($mapItem->overlibheight != 0) {
                        $above = "HEIGHT," . $mapItem->overlibheight . ",";
                        $img_extra .= " HEIGHT=$mapItem->overlibheight";

                        if ($mid_y > $center_y) {
                            $above .= "ABOVE,";
                        }
}

                    foreach ($dirs as $dir => $parts) {
                        $caption = ($mapItem->overlibcaption[$dir] != '' ? $mapItem->overlibcaption[$dir] : $mapItem->name);
                        $caption = $this->ProcessString($caption, $mapItem);

                        $overlibhtml = "onmouseover=\"return overlib('";

                        $n = 0;
                        if (sizeof($mapItem->overliburl[$dir]) > 0) {
                            // print "ARRAY:".is_array($link->overliburl[$dir])."\n";
                            foreach ($mapItem->overliburl[$dir] as $url) {
                                if ($n > 0) {
                                    $overlibhtml .= '<br />';
                                }
                                $overlibhtml .= "<img $img_extra src=" . $this->ProcessString($url, $mapItem) . ">";
                                $n++;
                            }
                        }
                        # print "Added $n for $dir\n";
                        if (trim($mapItem->notestext[$dir]) != '') {
                            # put in a linebreak if there was an image AND notes
                            if ($n > 0) {
                                $overlibhtml .= '<br />';
                            }
                            $note = $this->ProcessString($mapItem->notestext[$dir], $mapItem);
                            $note = htmlspecialchars($note, ENT_NOQUOTES);
                            $note = str_replace("'", "\\'", $note);
                            $note = str_replace('"', """, $note);
                            $overlibhtml .= $note;
                        }
                        $overlibhtml .= "',DELAY,250,${left}${above}CAPTION,'" . $caption
                            . "');\"  onmouseout=\"return nd();\"";

                        foreach ($mapItem->imap_areas as $area) {
                            $area->extrahtml = $overlibhtml;
                        }
                    }
                } // if change
            } // overlib?
// now look at infourls
            foreach ($dirs as $dir => $parts) {
                foreach ($parts as $part) {
                    # $areaname = $type . ":" . $prefix . $mapItem->id . ":" . $part;

                    if (($this->htmlstyle != 'editor') && ($mapItem->infourl[$dir] != '')) {
                        foreach ($mapItem->imap_areas as $area) {
                            $area->href = $this->ProcessString($mapItem->infourl[$dir], $mapItem);
                        }
                    }
                }
            }
        }
    }
howardjones commented 5 years ago

Yes, but that looks right too 🤔 (the important part is the $dirs= near the top - so it definitely should be trying to get both the IN and OUT).

Oh wait... it writes the same $overlibhtml to all the $imap_areas, just above that // overlib? comment. That's not right - it should only write to the ones for that direction. So the last direction written (OUT) overwrites the earlier one.

And it's still like that in the current version, too. So it's a legit bug :-) I'll figure out a solution. The variables have changed name, but the current version is basically the same, so the fix will work for you, too.

jpobeda commented 5 years ago

oh yeahhhhhhhhhhh =D I bet you weren't expecting that hehehe

howardjones commented 5 years ago

Should be fixed now in master.