Yeti syslog

Well, this is my working name of the project – yeti syslog.

I decided don't use any big third-party components. Most of code is Delphi 7 native.

So, the work consist of 3 parts – the syslog service, the interface part, and the installer.

Yes, not all parts are completed. Therefore any part can be changed, may be not whole, but some things.

Interface part

Consist of the form with 3 pages (4th page – temporary for testing purposes). Also the tray icon, that allow to see the settings and change them.

All settings are saved into the registry – key HKEY_LOCAL_MACHINE

Service part

The service is working from registry settings, it doen't save anything into registry (although for now I saved the time when last logs was ent to syslog).

The installer

I use recent InnoSetup installation utility.

The installer – install both interface part and services into the system.

Current variant install the interface part.

Units

syslog_pref

Contain two classes that read data from registry into the properties.

Also it save changed variable back into registry.

This unit is used by both parts – by the interface and the service.

syslog_interface

The interface form that consist of 3 pages based on initial 3 gifs.

Runtime_service_unit

The service unit

Trayicon

Simple component with tray icon + popup menu. Was used it in some my projects, not well commented, but working fine.

syslog_writer

Used as syslog facility, email about bugs, etc. For now – it write messages into the windows/temp directory, file “test_output.txt”. (note: in Win 2008 R2 – a 'temp' directory is under /users/…/application data/)

18-dec-2011

Testing in Windows 2008 Server R2 64-bit – both *.EXE being compiled by Delphi 7.0 – not working correct with eventlog, but everything fine after recompile them in the Delphi 2007. Resume – use Delphi 2007 to compile the final release.

28-dec-2011

Many things were refined. Now we can see that this work is completed by 85%.

Concepts

Transaction

When the service read messages from the eventlogNT, and lines from monitored files – it should send them out to syslog. We can define this process as a “transcation”. If transaction fail – the program will not update the Last_events[k] and lastsize[k] variables.

After 'try_cnt' fails – it sends out an email about this on defined email if any.

Successful – the program update the values:

  • Last_events[k] (k=0..2) – the datetime from where the program should take new messages from the eventlogNT; this parameter it keeps in the registry in the 'General' folder of the service application – 3 parameters “Last_events_0”, “Last_events_1”, “Last_events_2” format binary (datetime/double, 8 bytes)
  • Files[k].Last_Size (k=0..monitored_files_cnt-1] – the last size of the monitored file. We can think about if the file was appended – we read all new lines and send them into the syslog. If the file become smaller then their last_size – the program load all lines from this file.

Last_events processing

All messages from the eventlogNT are read in the reverse order (from latest back to oldest), result – the TStringList variable. On successful transaction – it takes the DateTime “Generated” value from the latest message and place it into the “Last_events” variable.

Last_size processing

Ok, as I mentioned before, every monitored file has the last size – the length of the file in bytes. The program is thinking about the file size is grows up. Every time the program open the file, seek into the position of previous size, and read all new bytes into the “buffer” in the binary mode. The it split this buffer into TStringList variable by #10 and #13 (usual windows line breaks).

In the case if last_size less then the current size – the program thinks about the monitored file was rewritten from scratch and read all lines from their beginning.

Cross compability Delphi 7 / 2007

Inside the code were added the compiler directives on the (“$IF CompilerVersion >= 18.5”) – to have the same code both for Delphi 7 and Delphi 2007. Yes, in these IDE some parameters where renamed. The Indy TIdSyslog component was changed in the Delphi 2007 edition.

Also recent TIdSyslog component has the ipv6 support when old had not.

Note: I don't found any ready-to-use freeware Delphi component that support the TCP protocol for syslog connections. Therefore if you have any – send me it to use. Otherwise I can not to implement TCP for syslog, only UDP + ipv4/ipv6. I'm an usual system programmer, do not understand details of the protocols UDP/TCP and how to program them.

Delphi 2009 and later (UTF-8 issues)

About Delphi 2010 – I assume you should compile the code in the compatible with old Delphi mode because of there are a lot of code that use 'string' type for low-level binary operations and this code is thinking about in this 'string' one byte = one character.

The same as 1 'char' = 1 byte.

I think it's not needed for the source code of the service (“Runtime_service.dpr”) and the interface part (“Yeti_syslog.dpr”) – to use UTF-8 string from the Delphi 2009/2010/XE/XE2.

And if you'll want to make 64-bit applications in the recent Delphi XE2 – I think it'll be no problem.

New eventlogNT reader unit

I decided to use ready and prooved source for this part. There is unit 'EventLog'. It uses the part of JEDI library (“JwaWin*”). Ok, I added this unit and the part of JEDI library (several uncommented *.inc, *.pas files). The URL from where they were taken – http://code.google.com/p/delphi-wmi-class-generator/source/browse/trunk/units/?r=30

The 'EventLog' unit has the detailed description, and I placed it here.

Debugging mode

We can not to run the program under debugger on different OS, therefore for testing we should use some another way to see how the application work, and to know where it'll has errors.

File 'debug.txt' – being exists in the directory with the service will enable the service to write out the file 'yeti_debug#####.txt' in the appent mode where it'll log every points in/out into procedures to have a log. Where ##### is a timestamp when the program was started.

syslog/first.txt · Last modified: 2012/01/15 13:33 by yetidi
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki