Access local services via openhab cloud connector


(Sander Brauns) #1

Hi all,

Is it possible to access a local service like grafana or frontail via myopenhab?
I would expect this to be possible, i have been looking around but can not seem to find any information about this.

Thanks,

Sander


(Markus Storm) #2

These are separate services to run on your local box (openHABian?) and unrelated to OH itself and it’s cloud interface.
Whatever you mean by “access” I guess would mean to log into your box, plus eventually have a (direct) web interface, and while there’s tools you can setup to use SSH or HTTP from a remote location to your box, myopenhab is none of those. Apart from that trying to do so does not make sense to me.


(Joachim Boeddeker) #3

No, this is not possible. Myopenhab is not a complete redirection to your openHAB host, it just exposes some openHAB structures to the internet.


(Sander Brauns) #4

Maybe I first had to explain what my goal was.
What I want to accomplish is that I can display these services in my openhab dashboard.
These work fine as long as I am in the local network.

Thanks.


(illnesse) #5

Just render it all into static files and put it into html/, then reference it through /static/ via image/webview in your sitemap, pro-tip: refresh it via sh script and exec command, works great with grafana every 5min (i render mine as transparent pngs), frontail wouldn’t be as smooth as realtime of course, maybe grep the last 100 log messages and display it with some css in a webview, add some ajax to refresh it every couple seconds. :sunglasses:


(Christian) #6

This would be a nice feature to integrate into the whole OH2 concept. Since the frontail is such a great tool and plays a central role in the users setup, It should be integrated to the openhab cloud connector. It would make it a even more complete package. JMHO…


(Rich Koshak) #7

No, it is clear what you want to do. It just cannot be done. That is not the purpose of myopenhab.org and the cloud connector binding. Only the OH REST API gets exposed to myopenhab.org. It is not a full reverse proxy and probably never will be.

Well, frontail is not part of openHAB, nor is Grafana nor any of the dozens of external web based applications people have on their LAN and may want to access on their sitemaps. But that isn’t likely to ever happen because doing so is very challenging to do securely and would require orders of magnitude more server resources than our already somewhat stressed myopenhab.org servers are under.

If you want to access these outside your LAN, you need to set up your own reverse proxy. You should be able to use the OH reverse proxy docs to add additional services to the reverse proxy.

Alternatively, you can set up an ssh tunnel or a personal VPN to access these services when not at home. Personally I recommened one of these approaches over the reverse proxy approach. If you don’t have the knowledge and skills to know to set up a reverse proxy already, you probably do not have the skills and knowledge to secure the reverse proxy and monitor it for compromise.


(illnesse) #8

@sbrauns i actually just replaced frontail on my sitemap with this, it’s just a quick hack, needs some more functionality like syntax highlighting and testing, but it should be better than frontail, performance wise and it works with myopenhab.org

logtail.html

<head>
    <script src="../static/js/jquery.min.js"></script>
    <style>
        body
        {
            overflow: hidden;
        }

        .s1
        {
            color: #666;
        }

        .s2
        {
            color: #a25050a6;
        }

        .s3
        {
            color: #ba9f669d;
        }


        #logview
        {
            height:100%;
            color: #aaa;
            font-family: monospace;
            font-size: 9px;
            overflow: hidden;

            white-space: pre-wrap;       /* css-3 */
            white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
            white-space: -pre-wrap;      /* Opera 4-6 */
            white-space: -o-pre-wrap;    /* Opera 7 */
            word-wrap: break-word;       /* Internet Explorer 5.5+ */
        }

    </style>
</head>
<body>
    <pre><div id="logview"></div></pre>
    <script type="text/javascript">
        $( document ).ready(function()
        {

            var syntaxhilight = true;

            setInterval(function()
            {
                $.get( "/static/openhablog_tail.log", function( data ) 
                {
                    if (syntaxhilight)
                    {
                        var lines = data.split("\n");
                        var out = "";
                        var class1 = "s1";
                        $.each(lines, function(n, elem) 
                        {
                            if (elem.indexOf("[ERROR]") >= 0)
                            {
                                class1 = "s2";
                            }
                            else if (elem.indexOf("[WARN ]") >= 0)
                            {
                                class1 = "s3";
                            }
                            else class1 = "s1";

                            out += "<span class=\""+class1+"\">" + elem + "</span>\n";

                        });
                        console.log(out.length)
                        $("#logview").html(out);                    }
                    else
                    {
                        console.log(data.length)
                        $("#logview").html(data);
                    }

                    $('html, body').scrollTop($(document).height());
                });
            },2000);
        });
    </script>
</body>

thing

Thing exec:command:logtail [command="/etc/openhab2/scripts/sh/logtail.sh", interval=2, timeout=250]

item

String logtail "logtail" { channel="exec:command:logtail:output" }

logtail.sh

tail -50 /var/log/openhab2/openhab.log > /etc/openhab2/html/openhablog_tail.log

sitemap

Webview url="/static/logtail.html" height=14

(sujit) #9

really nice approach. Open door for lot of monitoring scenarios
will this work in myopenhab.org or mobile app ?


(illnesse) #10

doesn’t seem to work in the app - but neither does my google map, does the app support webviews at all?


(Sander Brauns) #11

Oh right, that is a nice way to go. I am using habpanel, I guess this would work perfectly with habpanel.
Thanks a lot for the example!


(illnesse) #12

edited my post to add some simple error/warning highlighting, removed scrollbars etc, reduced output to 50 lines


(illnesse) #13

Actually, i probably should put this and my other stuff on github and link it here… when time allows it. I’ve been working on the log view thing some more and i think it’s worth sharing


(Michael Ingraham) #15

@illnesse,

I got it working. The biggest issue is that it’s not displaying all of the end of the openhab.log. The window (height=14) is not big enough for the 50 lines. I changed it to 48 lines to fit. Is there a way to add a vertical scroll bar so that the “truncated lines” can be displayed?

I decided to emulate frontail by merging the openhab and events logs. The merge takes a few seconds to complete so I increased the refresh interval to be higher than every two seconds. Here is the command that interlaces the two log files (credit):

sort -nbms -k1.1,1.4 -k1.6,1.7 -k1.9,1.10 -k1.12,1.13 -k1.15,1.16 -k1.18,1.19 -k1.21,1.23 /srv/openhab2-logs/openhab.log /srv/openhab2-logs/events.log | grep . | tail -48 > /srv/openhab2-conf/html/openhablog_tail.log

Also, to get the example to work required:

  • I needed to obtain jquery.min.js. I found jquery-1.11.0.min.js on my RPi installation so I used that.
  • I needed to install the REGEX transformation
  • I needed to install the EXEC binding.

What actually triggers the .sh script to execute? I understand that Thing definition and the Item referring to the Thing. But then I don’t see that the Item is referred to… which I assume would be what gets the script to execute to generate the log segment. I’d love to understand where they get invoked. I don’t see them referenced explicitly in the HTML nor in the sitemap.

Thanks.

Mike