Jump to content

my syslog server with mailsending


memnon
 Share

Recommended Posts

Hello,

i made my fist (beta)project for this issue

i´m shure it can be done better, but it works as demo for me to built on it :P

the programm is used, to get info from a hardwarefirewall (you have to enter there the ipadress you run this programm). the syslog is displayed in a messagebox, its written to a logfile in the tempfolder and its sent via email.

it installs DURING the use 2 services to send mails, the services will be autoremoved on exit. therefor you need administration rights.

you need ezmts - you can google for it.

then change the settings to your needs...

i tried this (with changed settings) on 5 different clients and it worked as it should :lmao:

#Include <Date.au3>

#include <GUIConstants.au3>

#include <Process.au3>

Dim $sData[14]

Dim $sRecv[14]

;Syslog Settings

$logfile = @tempdir & "\autoit-syslog.txt"

$udpport = 514

;EzMTS

$Mailpath=@tempdir & "\ezmts"

if not FileExists($mailpath &"\") then DirCreate ($mailpath)

Msgbox (0,"test",$MailPath)

FileInstall("D:\sich\ezmts\EzMTS.Alias", $Mailpath & "\EzMTS.Alias")

FileInstall("D:\sich\ezmts\EzMTS.INI", $Mailpath & "\EzMTS.INI")

FileInstall("D:\sich\ezmts\EzMTS.Lists", $Mailpath & "\EzMTS.Lists")

FileInstall("D:\sich\ezmts\EzMTS.Pass", $Mailpath & "\EzMTS.Pass")

FileInstall("D:\sich\ezmts\EzMTS.Retry", $Mailpath & "\EzMTS.Retry")

FileInstall("D:\sich\ezmts\EzMTS.User", $Mailpath & "\EzMTS.User")

FileInstall("D:\sich\ezmts\MTSAgent.exe", $Mailpath & "\MTSAgent.exe")

FileInstall("D:\sich\ezmts\MTSSmtp.exe", $Mailpath & "\MTSSmtp.exe")

FileInstall("D:\sich\ezmts\POP3.Auth", $Mailpath & "\POP3.Auth")

DirCreate($Mailpath &"\Archive")

DirCreate($Mailpath &"\dir")

DirCreate($Mailpath &"\inbox")

DirCreate($Mailpath &"\Postmaster")

DirCreate($Mailpath &"\Root")

$Domain0="something to be resolved.at" ;this domain must be able to be dns resolved

$PrimaryDNS="195.3.96.67" ;DNS Server1

$SecondaryDNS="195.3.96.68" ;DNS Server2

$Port="26" ;i used 26, to no conflict other mailserver which use port 25 at default

$Mask0="192.168.1.*" ;this is the iprange what can use the server

IniWrite( $Mailpath & "\EzMTS.Ini", "All", "Domain0", $Domain0)

IniWrite( $Mailpath & "\EzMTS.Ini", "All", "MailPath", $Mailpath)

IniWrite( $Mailpath & "\EzMTS.Ini", "Agent", "PrimaryDNS", $PrimaryDNS)

IniWrite( $Mailpath & "\EzMTS.Ini", "Agent", "SecondaryDNS", $SecondaryDNS)

IniWrite( $Mailpath & "\EzMTS.Ini", "SMTP", "Port", $Port)

IniWrite( $Mailpath & "\EzMTS.Ini", "LocalUserIP", "Mask0", $Mask0)

sleep (2000)

_RunDOS ( $Mailpath & "\MtsAgent.exe /install")

_RunDOS ( $Mailpath & "\MtsSmtp.exe /install")

_RunDos ("net start ""Mail Transport Agent""")

_RunDos ("net start ""Mail Transport SMTP Server""")

sleep(2000)

;Mailsettings

$MailserverIP = @IPAddress1

$MAilFrom = "memnon@yahoo.de" ;your emailadresses here

$RcptTo = "memnon@yahoo.de" ;your emailadresses here

$From = "Firewall"

$Subject = "Syslog"

$sData[1] = "HELO " & $From & @CRLF

$sData[2] = "MAIL FROM: <" & $MAilFrom &">" & @CRLF

$sData[3] = "RCPT TO: <" & $RcptTo &"> "& @CRLF

$sData[4] = "DATA" & @CRLF

$sData[5] = "From:" & $From & "< " & $MAilFrom &" >" & @CRLF

$sData[6] = "To:" & $RcptTo & @CRLF

$sData[7] = "Subject:" & $Subject & @CRLF

$sData[8] = "Sender: Microsoft Outlook Express 6.00.2800.1158" & @CRLF

$sData[9] = "Mime-Version: 1.0" & @CRLF

$sData[10] = "Content-Type: text/plain; charset=US-ASCII" & @CRLF

$sData[11] = @CRLF

$sData[13] = "." & @CRLF

UDPStartup()

$socket = UDPBind(@IPAddress1, $udpport)

If @error <> 0 Then Exit

While 1

$data = UDPRecv($socket, 1024)

If $data <> "" Then

MsgBox(0, "UDP DATA", $data, 1)

$file = FileOpen($logfile, 1)

If $file = -1 Then Exit

FileWriteLine($file, _Nowdate() & " " & _DateTimeFormat( _NowCalc(),4) & " " & $data )

FileClose($file)

$sData[12] = $data & @CRLF

TCPStartUp()

$socketm = TCPConnect(TCPNameToIP($MailserverIP), 26)

If $socketm = -1 Then Exit

for $i=1 to 13

sleep(200)

$srecv[$i]=TCPSend($socketm, $sData[$i])

next

sleep(200)

TCPCloseSocket($socketm)

TCPShutdown()

;Mailstatus <> 3 = Fehler beim Versenden des Mails

if $srecv[13]<>"3" Then

$file = FileOpen($logfile, 1)

If $file = -1 Then Exit

FileWriteLine($file, _Nowdate() & " " & _DateTimeFormat( _NowCalc(),4) & " " & $data[$i] & "Error sending File !" )

FileClose($file)

endif

EndIf

WEnd

Func OnAutoItExit()

UDPCloseSocket($socket)

UDPShutdown()

sleep(2000)

_RunDOS (@tempdir & "\ezmts\MtsAgent.exe /remove")

sleep(2000)

_RunDOS (@tempdir & "\ezmts\MtsSmtp.exe /remove")

sleep(2000)

If FileExists($Mailpath & "\") Then DirRemove($Mailpath, 1)

EndFunc

das beste Windows Support Forum: Windows 2000 Helpline und tschüss den WindowsfehlernProgrammieren: Autoit 3 - wer braucht noch VBS ?!Programmieren: Autoit 3 Forum?

Link to comment
Share on other sites

  • 7 months later...

handy bit of code.

I tried it out with out using the mail send features, I found that it couldn't keep pace with our current syslog requirements.

out of 28,357 (in 2 minutes) it only logged 11,110 of them. anyone suggest a way of adding buffering to support the load with out dropping messages ?

i'm wanting to use this code and develop it further but if it can't handle the load or if auto it isn't "quick" enough, then I'll have to go to another language.

Link to comment
Share on other sites

i'm wanting to use this code and develop it further but if it can't handle the load or if auto it isn't "quick" enough, then I'll have to go to another language.

why do you want to develop a new syslog server? There are plenty of them available in the internet. Most of them are free and ways more capable than any software you can write in the next 1-2 years...

I would recommend syslog-ng.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

I don't exactly want another syslog clone.

I want to enhance my build system to report to a central location instead of using local log files.

so, being able to receive system messages across the network in one location, I could then enhance the build system to do patch deployment, printer deployment, you name it.

how many of us have built small apps to install a new application update ? and never know exactly how many machines and at what time it was installed ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...