Translate

Saturday, March 26, 2011

Apache log messages on the Infoglobe

The RS232 version of the Infoglobe Interface  is capable to receive RS232 messages from a system, not only from a terminal emulator.
So, in order to test this capability, here a note about how to create a "custom" log message from the server Apache and have it sent to the interface.
 
In order to send a log message to the interface, we have to create a specific log capable to "fit" the Infoglobe message length.
The infoglobe is capable to display a maximum of 36 characters and also some characters are not available.
Because of that we have to create a log with the minimum information possible.

Log generation

Fortunately is quite simple to create custom log files with Apache.
It's enough to open the http server configuration file (in my case, on CentOS  /etc/httpd/conf/httpd.conf) and create a log generation customized for our needs.
In this configuration file, just search for the word LogFormat.
Usually there are some LogFormat lines in the file.
We have to create our own. Here the line I prepared :
LogFormat "^%{%D,%T}t %h " infoglobe

Basically I want to display only the date/time of the access and the IP.
%t display the time, but since the default format is quite huge, I used the strtime format to create a shorter date/time string.
You can find more information about the log capabilities of Apache in the Apache documentation.

Then in the part of the configuration file where the server is defined (in my case a Virtual server) just create a log entry using the LogFormat you prepared.
In my case :

CustomLog logs/apkh_infoglobe infoglobe


Now every time someone access the server, a file called apkh_infoglobe will contains date/time and IP of the access, something like :

^08/12/07,15:00:04 68.46.241.153

Note the first character.
When the Infoglobe interface receive the character '^' will display the message in rotation.

Log presentation

After restarting the server (every modification to the configuration file will require a restart of the server), every access will add a line the log file.
To send the log file, in automatic way, to the Infoglobe, is enough to use this command, assuming of course the /dev/ttyS0 (equivalent to COM1 under DOS) is connected to the Infoglobe interface :

# tail -f -n 1 log_file > /dev/ttyS0

In my example :

# tail -f -n 1 apkh_infoglobe > /dev/ttyS0

After that, every access to the server will be showed up on the Infoglobe.
That's it !

Here an extract of the log file apkh_infoglobe :

.....................
.....................
^08/15/07,00:05:47 68.46.241.153
^08/15/07,00:05:34 68.46.241.153
^08/15/07,00:05:47 68.46.241.153
^08/15/07,00:05:26 68.46.241.153
^08/15/07,00:05:52 68.46.241.153
^08/15/07,00:06:05 68.46.241.153
^08/15/07,00:06:05 68.46.241.153
^08/15/07,09:26:59 68.46.241.153
^08/15/07,09:27:03 68.46.241.153
^08/15/07,11:17:41 66.249.66.40
^08/15/07,11:17:41 66.249.66.40
^08/15/07,11:22:37 68.46.241.153
^08/15/07,11:22:43 68.46.241.153
^08/15/07,11:22:44 68.46.241.153
^08/15/07,11:22:46 68.46.241.153
^08/15/07,11:22:46 68.46.241.153
^08/15/07,11:22:46 68.46.241.153
^08/15/07,11:22:46 68.46.241.153
^08/15/07,11:22:47 68.46.241.153
^08/15/07,11:22:47 68.46.241.153
^08/15/07,11:22:47 68.46.241.153
^08/15/07,11:22:47 68.46.241.153
^08/15/07,11:22:47 68.46.241.153
^08/15/07,11:22:51 68.46.241.153
^08/15/07,11:22:56 68.46.241.153
^08/15/07,11:23:00 68.46.241.153
^08/15/07,11:23:00 68.46.241.153
^08/15/07,11:23:02 68.46.241.153
^08/15/07,15:46:05 74.6.19.79
^08/15/07,16:46:31 66.249.66.40
.....................
.....................

Important to remember that the tail command is sending always the LAST line as soon as it is generated.
Here a picture of the Infoglobe showing the temperature :

infoglobe_temp.jpg
Here the Infoglobe showing an IP from the log :
infoglobe_ip1.jpg

2 comments:

  1. Hi, My embedded board is still in the mail so I am only able to use my imagination to what can be done with it. I have coded up the arduino code and the python parts to get the weather/news to the info globe. That will have to wait till the controller arrives.
    You mention the RS232 version of the infoglobe. I am assuming it is a version that you implemented. Could you elaborate (I need to experiment on it once I have my setup) as to what transitions you use to show 1 line of message, wait for a sufficient amount of time and then show the next line of message. What would be a good way to split up a message larger than 35 bytes to display smoothly without any breaks/ pauses.

    Thanks,

    Raj
    p.s. I see you have a tail 1 - so it is just one line. Is there any workaround to show the unsupported characters like %&+; etc

    ReplyDelete
  2. Hi RR
    The interface I built is a RS232 version. I originally planned to use ZigBee for the connection but I didn't do anything else so far, too busy with other things (somebody call that "life" :-) ).
    About your other question ... well hard to say.
    By it's nature, Infoglobe is great to display short messages, there is no an easy way to display messages longer than 36 chars and "bind" together messages is only good to leave you with headache :-)
    Under normal use I doubt you can stare to the Infoglobe more than few seconds, i.e. is great for alarm/short messages, not to read weather reports or news.
    Maybe it's just me, but the bottom line is that I never explored how to bind long messages because I considered it useless.
    In this example (Apache log) I reduced the useful info into 36 characters.

    And for the unsupported characters, I didn't do much. I remember to have seen something time ago but I never did experiment.
    I have also a Infoglobe color (!!) to modify and I suppose it has extra code to manage the color (you can change the message color !).
    But until now I'm working on other stuff :)

    ReplyDelete