Displaying log texts in openhab

Hi,

I’m looking for a way to display login attempts on my server through openhab. I think i can figure out how to send strings to items and store them using persistence, but could anyone tell me how such information can be displayed in openhab the best way? A simple text-box with log lines for the let’s say the last week would be great, but I have not found any example like this.

Thanks in advance!

There’s no multiline text-box widget for openHAB site maps. You could do what you want with a Webview widget. However, this would require some programming. For example, you could periodically scan the log files, extract the login records, format them as an HTML table and save it somewhere where it could be loaded by a Webview widget via a URL.

Ok, that’s clear. Thanks for the fast answer!

I solved it in the end by simply making a cronjob that creates a text file with the log data in the /var/www/ directory (I’m using linux). In openhab I use the webview widget and point to the specific text file like this:

Webview url="http://debian-armhf.fritz.box/fail2ban.txt" height=20

Works quite well.

One remaining question: I tried “localhost” instead of the LAN address, but it didn’t find the file. My guess is that localhost is interpreted as the IP of the client, rather than the server. Does anyone know how to solve this? (feels silly to refer to the LAN address when the files are already on the same computer)

Hi

Just an idea: If your webserver is not bound to the localhost interface but only to the network interface (2 different things on Linux), you might use the file: url: file://var/www/fail2ban.txt if the file is readable from your openhab user.

As I’ve said: just an idea without any warranty :wink:

Regards
Dieter

Good idea, but it doesn’t seem to work sadly… I tried file://var/www/fail2ban.txt and file:///var/www/fail2ban.txt. There is no complaining that it cannot find it, as it does when there is a wrong website path, but there is also no content shown.

If fact I was looking for some log message telling me more, but none of the /var/log/openhab/ files seem to say anything (without tampering with /etc/openhab/logback.xml at least)

Hi

When I think about it again, I’m not sure whether or not this idea was so good. First problem could be: has your Openhab user read access to the file? Second: What is done by the widget, does it really care about the given protocol or use http anyway? For your original problem (this was only a workaround) try to use wget or similar to get the file from localhost (assuming that your openhab is on the same computer than the file, otherwise we have the reason why it’s not working ;-)).
Even if that doesn’t work (hopefully it shouldn’t) it might give you more information.

So trying wget http://localhost/fail2ban.txt will clarify things. If it works there is a problem with the widget, otherwise there is a problem with your server configuration (even if I’m not sure about having such a file available for the whole wide world…)

Regards
Dieter

Please forgive my confusion, but I’m not understanding this discussion. The Webview widget is a client-side presentation component. The browser client will try to load the Webview URL the same as any other web page. If the URL refers to localhost, it will attempt to retrieve the content from a server on the client computer, not on the server. To use the file: protocol the server file system must be locally mounted on the client computer at the path specified in the URL. It will not work in the general case when the server file system is not mounted locally.

If you don’t want to specify the server host name and port, one approach is to return the file from the openhab server and use a relative URL. I’ve heard it’s possible (but not recommended) to serve user-created static files from the openhab server, but I don’t know how to do it. Maybe someone else can comment on that.

Hi
Now I’m a bit confused: The client (the computer displaying the frontend) tries to load the Webview URL??? In my oppinion the openhab server is trying to get the data and send it to the client computer who just did the rendering of the received data. If that is true, it is completly impossible to use the file protocol or the localhost adress, as this must be available on every possible client including smart-phone, -watch, -etc.

Regards
Dieter

My understanding is that the Webview is rendered in an iframe element that loads the content (on the client side) from the URL specified for the widget. I don’t have an easy way to double-check that at the moment.

Ok, in that case I revoke all my postings in this thread :wink:

Indeed that was my fear from the beginning… I’ll simply use the DNS path then and be happy. Thanks for your time!

Hi
That’s probably the best way to do it…

But, nevertheless, it might not solve your problem completly (sorry, but I work in Software Testing and it’s my job to find things that probably won’t work ;-)): When the query is done by your client (e.g. smart-) it is quite sure that this device doesn’t have access to this (LAN) URL when you’re away from home, unless you really make it public to the world and even then you need a public DNS name.
You might give it a try one day…

Regards
Dieter

Yes. For now when I use openhab remotely, I tunnel to my LAN at home, and configure the web browser to use it as a proxy server (possible with Firefox on Android it turns out!). So not really an issue for me.

If I want to make it public I probably want a DNS name for openhab itself, so I could use the same for the file (although then anyone can see the file of course)

Hi!
I’m having a related problem, not regarding the log file function but what is expressed in the later question by ulfwin.

One remaining question: I tried “localhost” instead of the LAN address, but it didn’t find the file. My guess is that localhost is interpreted as the IP of the client, rather than the server. Does anyone know how to solve this? (feels silly to refer to the LAN address when the files are already on the same computer)

My webview content is public through the use of a DDNS service. I can access my Openhab from outside my router, externally, but the DDNS address can’t be resolved while I’m at home on the LAN. After reading some posts on the web I’m positive that this has something to do with lack of possibility to resolve the DDNS address locally, either through a so called loopback by my router (or a static DNS entry in the router ) or perhaps a hosts definition in the Raspberry Os.

For information: I’m running an Apache2 server, on the same Raspberry as the Openhab server, hosting a RPi-web-cam interface and some py-scripts.

Help with this problem is much appreciated!

Hi Niklas

From my understanding: your DNS Server (the router) requests a name and get’s it’s own (public) IP. So it decides not to produce outgoing traffic but to keep the request but, on the other hand, didn’t know what to do with the request as the forwarding rule you have in your router is only relevant for external, incomming traffic…

But the thing I’m wondering is: Are you asking just out of interest or do you really have a problem? Or, asked the other way round, if you don’t have a problem with the log file (content), why would you access your server internal by it’s DDNS name? If there is a problem with the content we’re back to the original problem of Ulf which can not really be solved besides using a VPN access when not at home (my understanding)
Nevertheless an interesstig new idea for “what else can go wrong” and “why this is not such a good idea to do it that way” :wink:

Regards
Dieter

Hi Dieter!

No this is an actual problem for me. As I want to be able to connect to my Openhab away from home I use a DDNS service which means that I’m pointing to this address in my weburl frame. But by doing this I’m unable to reach this content while at home as the DDNS adress is not resolved. My understanding and experience of this is the same as how steve1 explaines it.

One way of solving this could be for me to maintain two sitemaps which are more or less identical with the difference that the “local” sitemap referrs to the local address e.g. 192.168.0.xxx. But this feels like a very inefficient solution as I would need to maintain two sites.

Could I perhaps integrate my Apache2 web content in the sitemap in a different way which uses a more local solution? My thought was that I could “bounce” the DDNS request locally in the Raspberry through a hosts configuration or in my router (dlink dir825). I’ve looked in my router settings and I cant find a relevant option for this.

A VPN connection is of course also an option but that means that other users must also use the VPN. Although I have a Synology NAS so configuring a VPN is interesting for other reasons.

Note: I can reach the Openhab sitemap from my LAN using the local address but the weburl content in the sitemap cant be resolved.

@Frasier I’m probably not understanding the situation completely, but if your LAN router/gateway is configured properly you should be able to resolve any DNS address. DDNS is just referring to a technique of occasionally updating DNS data with a dynamically-assigned IP address.

Are you able to do an nslookup on the LAN for the DDNS hostname? If so, that will give some hints if the problem is some special LAN configuration. Otherwise, are you able to ping the DDNS hostname from the LAN? That will also attempt to resolve the name using DNS and display it.

So I’m clear, you are able to access the webview content from outside your LAN, right? (Just verifying that you have the Apache port open on the gateway.)

I might be referring to DDNS in the wrong way but I roughly understand its funtionality. But still if I’m trying to access a registered DNS address while in the LAN the connection attempt must still first reach a DNS server in order to point back to the accociated IP number and either way I find this step unneccesary as I already know that the host is local. The address lookup time could be a lot less if this step was eliminated in some way. I’ve read Dieters answer once more and perhaps its a matter of forwarding rules, I’ll look into that.

I will investigate using nslookup and ping later when I’m at home. thanks for your patience. And yes outside my LAN I can reach the Apache content.

Hi

I haven’t doubted that you are able to reach your Webview content from the outside. Without the exact protocol knowledge of DNS here is what’s going on when accessing the DNS from LAN:
The DNS Server in your router will query it’s master dns server (usually the dns of your ISP) for the ddns name. That server will return the WAN address of the router itself (Router DNS: “Who has <your>.<ddns>.<domain>”, ISP DNS: “you”). This will bring your router to the point and try to resolve the address by itself. As the internal DNS server goes only for the LAN part (where the router dns server is responsible) but the name belongs to the WAN part it is not able to resolve it if only the domain part does not match.
I’m not sure whether or not it is possible to configure your router to handle <ddns>.<domain> requests as well with his internal dns server and also configure your raspberry to react on these calls (normally yes, but not the standard setting) I can’t say as I haven’t done it myself yet.
As @steve1 just wrote the ddns is “just” dns and the nslookup will quite surely work and probably even the ping will work (in the end you are pinging your router) but with a little inteligence your router will notice that as well and then block itself out…

Regards
Dieter