Translate

Showing posts with label httpd. Show all posts
Showing posts with label httpd. Show all posts

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