znilTail/znilTail.au3
2018-10-08 14:51:26 +02:00

771 lines
32 KiB
AutoIt
Raw Permalink Blame History

#NoTrayIcon
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Icon=Icon256-32.ico
#AutoIt3Wrapper_Res_Description=Simple Tail Programm as an Zabbix Tool
#AutoIt3Wrapper_Res_Fileversion=1.0.1.12
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=2013 Bernhard Linz / Bernhard@znil.de
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1031
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt('MustDeclareVars', 1)
#Region ;************ Includes ************
#Include <Inet.au3>
#Include <ButtonConstants.au3>
#Include <StaticConstants.au3>
;~ #include <EditConstants.au3>;~~~
;~ #include <GUIConstantsEx.au3>;~~~
;~ #include <WindowsConstants.au3>;~~~
#include "_ChatBox.au3"
#EndRegion ;************ Includes ************
#Region ------ Dim Variables ------------------------------
Global $Form_znilTail
Global $EditTailText
Dim $ButtonStart
Dim $ButtonStop
Dim $ButtonOpen
Global $CheckboxHighlight
Global $CheckboxHideText
Global $InputHighlightText
Global $InputHidetext
Dim $ButtonFontMinus
Dim $ButtonFontPlus
Global $iFontsize = 9
Dim $nMsg
Dim $data
Global $bUseColorize = False
Global $bHideText = False
Global $TailFile = ""
Global $sFormTitle = "znilTail: No File selected"
Dim $aWndPos
Global $iTextLength = 0
Global $LabelCounter
Global $iRichEditTextLimit = 2147483647 ; 2GB - 1 Byte
Dim $ButtonHelp
Dim $i
Dim $zabbixAgentName
Dim $zabbixAgentConfigFile
Dim $hzabbixAgentConfigFile
Dim $iCurrentDebugLevel = 99
Dim $stemp
Dim $sRegSubKey
Global $bShowZabbixAgentButtons = False
Global $bAdminrights = False
Global $ButtonDebugLevel3
Global $ButtonDebugLevel4
Global $ButtonRestartAgent
Global $iTimer
Global $hControl
;Global $iRichEditTextLimit = 1048576
Dim $aRegistryBaseServicePaths[3] = ["HKLM\SYSTEM\CurrentControlSet\", _
"HKLM64\SYSTEM\CurrentControlSet\", _
"HKLM\SOFTWARE\Wow6432Node\SYSTEM\CurrentControlSet\"]
Dim $iRightRegistryPath
#EndRegion --- Dim Variables ------------------------------
Func _TailBoxCreate($gui,$txt,$x,$y,$w,$h,$bgc,$readonly,$autodetecturl, $style)
Local $ret;RichEdit
$ret=_GUICtrlRichEdit_Create($gui,"",$x,$y,$w,$h,$style)
_GUICtrlRichEdit_AutoDetectURL($ret,$autodetecturl)
;_GUICtrlRichEdit_SetLimitOnText($ret,-1)
_GUICtrlRichEdit_SetBkColor($ret,$bgc)
_GUICtrlRichEdit_SetReadOnly($ret,$readonly)
Return $ret
EndFunc
Func _znilTailAboutBox()
Local $AboutForm, $AboutGroupBoxFreeware, $AboutLabelFreeware1, $AboutLabelFreeware2,$AboutLabelFreeware3
Local $AboutButtonOK, $AboutLabelWeblink, $AboutGroupboxCommandline, $AboutLabelCommandline
Local $AboutLabelAuthor, $AboutLabelVersion, $AboutLabelContact, $nMsg2
Local $aWndPos
#Region ### START Koda GUI section ### Form=C:\_AutoIt\tail\znilTail-AboutBox.kxf
$AboutForm = GUICreate("About znilTail", 326, 244, 726, 446, BitOR($GUI_SS_DEFAULT_GUI,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetFont(8, 400, 0, "Courier New")
$AboutGroupBoxFreeware = GUICtrlCreateGroup("", 8, 8, 305, 81, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT))
$AboutLabelFreeware1 = GUICtrlCreateLabel("This Tool is FREEWARE!", 9, 16, 302, 35, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 16, 800, 0, "Courier New")
$AboutLabelFreeware2 = GUICtrlCreateLabel("Copy it, give it away,", 9, 48, 302, 18, $SS_CENTER)
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
$AboutLabelFreeware3 = GUICtrlCreateLabel("give it to others who need it!", 9, 64, 302, 20, $SS_CENTER)
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$AboutButtonOK = GUICtrlCreateButton("&OK", 238, 208, 75, 25, 0)
GUICtrlSetFont(-1, 12, 400, 0, "Courier New")
$AboutLabelWeblink = GUICtrlCreateLabel("http://znil.net", 9, 212, 222, 20)
GUICtrlSetFont(-1, 10, 400, 4, "Courier New")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor (-1, 0)
$AboutGroupboxCommandline = GUICtrlCreateGroup(" Commandline Call: ", 8, 160, 305, 41, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT))
$AboutLabelCommandline = GUICtrlCreateLabel("znilTail.exe [Path+Filename-to-Tail]", 12, 176, 299, 18)
GUICtrlSetFont(-1, 10, 800, 0, "Courier New")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$AboutLabelAuthor = GUICtrlCreateLabel("2013/2014 by Bernhard Linz", 8, 96, 305, 18)
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
$AboutLabelVersion = GUICtrlCreateLabel("Version: ", 8, 116, 305, 18)
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
$AboutLabelContact = GUICtrlCreateLabel("Contact: Bernhard@znil.de", 8, 136, 305, 18)
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetData($AboutLabelVersion, "Version: " & FileGetVersion(@ScriptFullPath))
$aWndPos = WinGetPos($AboutForm)
WinMove($AboutForm, "About znilTail", (@DesktopWidth - $aWndPos[2]) / 2, (@DesktopHeight - $aWndPos[3]) / 2, $aWndPos[2], $aWndPos[3])
While 1
$nMsg2 = GUIGetMsg()
Switch $nMsg2
Case $GUI_EVENT_CLOSE, $AboutButtonOK
GUISetState(@SW_HIDE,$AboutForm)
GUIDelete($AboutForm)
Return
Case $AboutLabelContact
_INetMail("Bernhard@znil.de", "- znilTail.exe -", "")
Case $AboutLabelWeblink
ShellExecute ("http://znil.net")
EndSwitch
WEnd
EndFunc
; #####################################################################################################################
Func _SetDebugLevelandRestartAgent($idebuglevel)
Local $aLinesInFile
Local $i
Local $bFoundLine = False
Local $hConfigFile
Local $oShell
_FileReadToArray($zabbixAgentConfigFile, $aLinesInFile)
For $i = 1 To $aLinesInFile[0]
If StringInStr($aLinesInFile[$i],"DebugLevel") > 0 And StringInStr($aLinesInFile[$i],"#") = 0 Then
If $bFoundLine = False Then
$aLinesInFile[$i] = "DebugLevel=" & $idebuglevel
$bFoundLine = True
Else
;ok we found it more than one time, set the other ones to a comment
$aLinesInFile[$i] = "#" & $aLinesInFile[$i]
EndIf
EndIf
Next
$hConfigFile = FileOpen($zabbixAgentConfigFile, 2)
For $i = 1 To $aLinesInFile[0]
FileWriteLine($hConfigFile, $aLinesInFile[$i])
Next
If $bFoundLine = False Then
;ok, we did not found the value, so we add him as last Entry
FileWriteLine($hConfigFile, "DebugLevel=" & $idebuglevel)
EndIf
FileClose($hConfigFile)
; File is rewritten, so restart the servcie
$i = Run(@ComSpec & ' /c net stop "' & $zabbixAgentName & '"', "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
$iTimer = TimerInit()
While ProcessExists("zabbix_agentd.exe") > 0
Sleep(100)
If TimerDiff($iTimer) > 10000 Then
ExitLoop
EndIf
WEnd
;Sleep(2000)
$i = Run(@ComSpec & ' /c net start "' & $zabbixAgentName & '"', "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
EndFunc ; ==>_SetDebugLevelandRestartAgent
; #####################################################################################################################
Func _GetDebugLevel()
Local $aLinesInFile
Local $i
Local $bFoundLine = False
Local $hConfigFile
Local $oShell
Local $iReturnValue
_FileReadToArray($zabbixAgentConfigFile, $aLinesInFile)
For $i = 1 To $aLinesInFile[0]
If StringInStr($aLinesInFile[$i],"DebugLevel") > 0 And StringInStr($aLinesInFile[$i],"#") = 0 Then
If $bFoundLine = False Then
$iReturnValue = StringReplace($aLinesInFile[$i],"DebugLevel=","")
$iReturnValue = StringReplace($aLinesInFile[$i]," ","")
$bFoundLine = True
EndIf
EndIf
Next
If $bFoundLine = False Then
$iReturnValue = 3
EndIf
Return $iReturnValue
EndFunc ; ==>_SetDebugLevelandRestartAgent
; #####################################################################################################################
Func _TailFile()
Local Static $TailPos = 0
Local $nBytes = 1024
Local $TailNew = ""
Local $sFile
Local $atemp
Local $sSearchStringHighlight
Local $sSearchStringHide
Local $i
Local $WhoHasFocus = ControlGetHandle($Form_znilTail, '', ControlGetFocus($Form_znilTail))
_GUICtrlRichEdit_PauseRedraw($EditTailText)
If $sFile Then
$TailPos = 0
EndIf
Local $Handle = FileOpen($TailFile)
If $Handle = -1 Then Return
FileSetPos($Handle, 0, 2)
Local $Size = FileGetPos($Handle)
If $TailPos = 0 Then
If $Size > $nBytes Then
$TailPos = $Size - $nBytes
EndIf
ElseIf $Size < $TailPos Then
$TailPos = $Size
EndIf
If $Size > $TailPos Then
FileSetPos($Handle, $TailPos, 0)
$TailNew = FileRead($Handle)
$TailPos = FileGetPos($Handle)
EndIf
FileClose($Handle)
_WinAPI_SetFocus($WhoHasFocus)
If $TailNew Then
_Tail_Content(True, $TailNew)
;_GUICtrlRichEdit_SetFont($EditTailText, $iFontsize, "Courier New")
;GUICtrlSendToDummy($idDummy)
$iTextLength = $iTextLength + StringLen($TailNew)
If $bUseColorize = True Or $bHideText = True Then
$atemp = StringSplit($TailNew, @CRLF)
$sSearchStringHighlight = GUICtrlRead($InputHighlightText)
$sSearchStringHide = GUICtrlRead($InputHidetext)
;ConsoleWrite($sSearchString & @CRLF)
$TailNew = ""
_WinAPI_SetFocus($WhoHasFocus)
For $i = 1 To $atemp[0]
If $bHideText = True Then
If StringInStr($atemp[$i], $sSearchStringHide) > 1 Then
$atemp[$i] = ""
EndIf
_WinAPI_SetFocus($WhoHasFocus)
EndIf
If StringInStr($atemp[$i], $sSearchStringHighlight) > 1 Then
;$TailNew = $TailNew & "[b][c=#FF0000]" & $atemp[$i] & "[/b][/c]" & @CRLF
_ChatBoxAdd($EditTailText, "[b][c=#CC0000]" & $atemp[$i] & "[/b][/c]" & @CRLF)
;_GUICtrlRichEdit_SetSel($EditTailText, _GUICtrlRichEdit_GetTextLength($EditTailText) - StringLen($atemp[$i]), -1)
;_GUICtrlRichEdit_SetCharBkColor($EditTailText, 0x00FF00)
;_GUICtrlRichEdit_SetCharBkColor($EditTailText, 0xFFFFFF)
Else
If $atemp[$i] <> @CRLF And $atemp[$i] <> "" Then
_ChatBoxAdd($EditTailText, "[c=#666666]" & $atemp[$i] & "[/c]" & @CRLF)
EndIf
EndIf
_WinAPI_SetFocus($WhoHasFocus)
Next
Else
_ChatBoxAdd($EditTailText, $TailNew)
_WinAPI_SetFocus($WhoHasFocus)
EndIf
_GUICtrlRichEdit_SetSel($EditTailText, 0, -1) ; go to end of text
_GUICtrlRichEdit_SetFont($EditTailText, $iFontsize, "Courier New")
_GUICtrlRichEdit_SetSel($EditTailText, -1, -1) ; go to end of text
;ConsoleWrite(StringLen($TailNew) & @CRLF)
EndIf
_WinAPI_SetFocus($WhoHasFocus)
GUICtrlSetData($LabelCounter, StringRegExpReplace(_StringReverse(StringRegExpReplace(_StringReverse($iTextLength),"\d{3}","\0.")),"(?<![0-9])\.","",1))
_WinAPI_SetFocus($WhoHasFocus)
If _GUICtrlRichEdit_GetTextLength($EditTailText) > ($iRichEditTextLimit - 524288) Then
_GUICtrlRichEdit_SetText($EditTailText, StringRight(_GUICtrlRichEdit_GetText($EditTailText, False, 1200), 524288))
EndIf
_GUICtrlRichEdit_ResumeRedraw($EditTailText)
;_WinAPI_RedrawWindow($Form_znilTail)
EndFunc ;==>_TailFile
; #####################################################################################################################
Func _Tail_Content($bSet = False, $sNew = "")
Local Static $Tail = ""
If $bSet Then $Tail = $sNew
Return $Tail
EndFunc
; #####################################################################################################################
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
Local $aWndPos = WinGetPos($Form_znilTail)
Local $iWidth = _WinAPI_LoWord($lParam)
Local $iHeight = _WinAPI_HiWord($lParam)
If $iWidth < 500 Then
$iWidth = 500
WinMove($Form_znilTail, $sFormTitle, $aWndPos[0], $aWndPos[1], $iWidth, $iHeight)
Else
EndIf
If $iHeight < 300 Then
$iHeight = 300
WinMove($Form_znilTail, $sFormTitle, $aWndPos[0], $aWndPos[1], $iWidth, $iHeight)
EndIf
_WinAPI_MoveWindow($EditTailText, 0, 38, $iWidth - 2, $iHeight - 102)
GUICtrlSetPos($CheckboxHighlight, 5, $iHeight - 61)
GUICtrlSetPos($InputHighlightText, 24, $iHeight - 59, $iWidth - 29)
GUICtrlSetPos($CheckboxHideText, 5, $iHeight - 32)
GUICtrlSetPos($InputHidetext, 24, $iHeight - 30, $iWidth - 29)
GUICtrlSetPos($ButtonOpen, $iWidth - 85, 4, 81, 30)
GUICtrlSetPos($LabelCounter, $iWidth - 217, 4, 123, 30)
GUICtrlSetPos($ButtonHelp, $iWidth - 257, 4, 33, 30)
Return 0
EndFunc ;==>WM_SIZE
; #FUNCTION# ====================================================================================================================
; Name...........: _StringReverse
; Description ...: Reverses the contents of the specified string.
; Syntax.........: _StringReverse($s_String)
; Parameters ....: $s_String - String to reverse
; Return values .: Success - Returns reversed string
; Failure - Returns an empty string and sets @error = 1
; |@Error - 0 = No error.
; |@Error - 1 = One of the parameters is invalid
; |@Error - 2 = Dll error
; Author ........: Jon
; Modified.......: SmOke_N (Re-written using msvcrt.dll for speed)
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _StringReverse($s_String)
Local $i_len = StringLen($s_String)
If $i_len < 1 Then Return SetError(1, 0, "")
Local $t_chars = DllStructCreate("char[" & $i_len + 1 & "]")
DllStructSetData($t_chars, 1, $s_String)
Local $a_rev = DllCall("msvcrt.dll", "ptr:cdecl", "_strrev", "struct*", $t_chars)
If @error Or $a_rev[0] = 0 Then Return SetError(2, 0, "")
Return DllStructGetData($t_chars, 1)
EndFunc ;==>_StringReverse
; #FUNCTION# ====================================================================================================================
; Name...........: _FileReadToArray
; Description ...: Reads the specified file into an array.
; Syntax.........: _FileReadToArray($sFilePath, ByRef $aArray)
; Parameters ....: $sFilePath - Path and filename of the file to be read.
; $aArray - The array to store the contents of the file.
; Return values .: Success - Returns a 1
; Failure - Returns a 0
; @Error - 0 = No error.
; |1 = Error opening specified file
; |2 = Unable to Split the file
; Author ........: Jonathan Bennett <jon at hiddensoft dot com>, Valik - Support Windows Unix and Mac line separator
; Modified.......: Jpm - fixed empty line at the end, Gary Fixed file contains only 1 line.
; Remarks .......: $aArray[0] will contain the number of records read into the array.
; Related .......: _FileWriteFromArray
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _FileReadToArray($sFilePath, ByRef $aArray)
Local $hFile = FileOpen($sFilePath, $FO_READ)
If $hFile = -1 Then Return SetError(1, 0, 0);; unable to open the file
;; Read the file and remove any trailing white spaces
Local $aFile = FileRead($hFile, FileGetSize($sFilePath))
;~ $aFile = StringStripWS($aFile, 2)
; remove last line separator if any at the end of the file
If StringRight($aFile, 1) = @LF Then $aFile = StringTrimRight($aFile, 1)
If StringRight($aFile, 1) = @CR Then $aFile = StringTrimRight($aFile, 1)
FileClose($hFile)
If StringInStr($aFile, @LF) Then
$aArray = StringSplit(StringStripCR($aFile), @LF)
ElseIf StringInStr($aFile, @CR) Then ;; @LF does not exist so split on the @CR
$aArray = StringSplit($aFile, @CR)
Else ;; unable to split the file
If StringLen($aFile) Then
Dim $aArray[2] = [1, $aFile]
Else
Return SetError(2, 0, 0)
EndIf
EndIf
Return 1
EndFunc ;==>_FileReadToArray
#Region ### START Koda GUI section ### Form=C:\_AutoIt\tail\znilTAIL.kxf
$Form_znilTail = GUICreate("znilTail: zabbix_agentd.log", 989, 483, 488, 278, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP))
GUISetBkColor(0x000000)
$EditTailText = GUICtrlCreateEdit("", 0, 38, 983, 377, BitOR($GUI_SS_DEFAULT_EDIT,$WS_CLIPSIBLINGS))
GUICtrlSetData(-1, "Edit1")
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
$ButtonOpen = GUICtrlCreateButton("Open File", 900, 4, 81, 30)
GUICtrlSetFont(-1, 8, 400, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "Open another Textfile for tailing")
$ButtonStart = GUICtrlCreateButton("START", 2, 4, 81, 30)
GUICtrlSetFont(-1, 12, 800, 0, "Courier New")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "START tailing the file.")
$ButtonStop = GUICtrlCreateButton("STOP", 88, 4, 81, 30)
GUICtrlSetFont(-1, 12, 800, 0, "Courier New")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetTip(-1, "STOP tailing!")
$CheckboxHighlight = GUICtrlCreateCheckbox("", 5, 418, 17, 25)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO+$GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$InputHighlightText = GUICtrlCreateInput("Highlight Lines with this Text", 24, 420, 958, 24)
GUICtrlSetFont(-1, 9, 800, 0, "Courier New")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
$ButtonFontPlus = GUICtrlCreateButton("+", 192, 4, 33, 30)
GUICtrlSetFont(-1, 20, 800, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "make Font bigger")
$ButtonFontMinus = GUICtrlCreateButton("-", 232, 4, 33, 30)
GUICtrlSetFont(-1, 20, 800, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "make Font smaler")
$CheckboxHideText = GUICtrlCreateCheckbox("", 5, 447, 17, 25)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO+$GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$InputHidetext = GUICtrlCreateInput("Hide Lines with this Text", 24, 449, 958, 24)
GUICtrlSetFont(-1, 9, 800, 0, "Courier New")
GUICtrlSetColor(-1, 0xFFFF00)
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
$LabelCounter = GUICtrlCreateLabel("LabelCounter", 768, 4, 123, 30, BitOR($SS_CENTER,$SS_CENTERIMAGE,$SS_SUNKEN))
GUICtrlSetFont(-1, 10, 800, 0, "Courier New")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000080)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP)
GUICtrlSetTip(-1, "Number of Bytes that have been read since start.")
$ButtonHelp = GUICtrlCreateButton("?", 728, 4, 33, 30)
GUICtrlSetFont(-1, 20, 800, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "About Box with link to Homepage")
$ButtonDebugLevel3 = GUICtrlCreateButton("Restart Zabbix Agent with DebugLevel=3", 292, 4, 153, 30, $BS_MULTILINE)
GUICtrlSetFont(-1, 8, 400, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "Change the DebugLevel of Zabbix Agent to 3 (Warnings) and restart the Agent. If this Button ist greyed Out you need to start znilTail.exe with Adminisrator-Rights. If no Zabbix Agent was found this Button will not shown.")
$ButtonDebugLevel4 = GUICtrlCreateButton("Restart Zabbix Agent with DebugLevel=4", 452, 4, 153, 30, $BS_MULTILINE)
GUICtrlSetFont(-1, 8, 400, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "Change the DebugLevel of Zabbix Agent to 3 (Debugging) and restart the Agent. If this Button ist greyed Out you need to start znilTail.exe with Adminisrator-Rights. If no Zabbix Agent was found this Button will not shown.")
$ButtonRestartAgent = GUICtrlCreateButton("Restart Zabbix Agent", 610, 4, 113, 30, $BS_MULTILINE)
GUICtrlSetFont(-1, 8, 400, 0, "Courier New")
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetTip(-1, "Just Restart the Zabbix Agent (without changing DebugLevel)")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#Region ------ StartUp ------------------------------
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUICtrlDelete($EditTailText)
$EditTailText = _TailBoxCreate($Form_znilTail,"",0, 38, 983, 377,"0xFFFFFF", True, False, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $WS_CLIPSIBLINGS))
_GUICtrlRichEdit_SetFont($EditTailText, $iFontsize, "Courier New")
_GUICtrlRichEdit_SetLimitOnText($EditTailText, $iRichEditTextLimit)
_WinAPI_SetWindowText($Form_znilTail, $sFormTitle)
GUICtrlSetData($LabelCounter, 0)
GUICtrlSetTip($ButtonDebugLevel3, "Change the DebugLevel of Zabbix Agent to 3 (Warnings) and restart the Agent." & @CRLF & _
"If this Button ist greyed out you need to start znilTail.exe with Adminisrator-Rights.")
GUICtrlSetTip($ButtonDebugLevel4, "Change the DebugLevel of Zabbix Agent to 3 (Debugging) and restart the Agent." & @CRLF & _
"If this Button ist greyed Out you need to start znilTail.exe with Adminisrator-Rights.")
;~ $data="[s]Hallo,[/s] [b][i]wie[/i] [u]gehts[/u]?[/b]"&@CRLF& _
;~ "[c=#00FF00]Gr<47>n"&@CRLF&"![/c]"&@CRLF& _
;~ "[c=#00FF00]Moinsen,[/c] schwarz"&@CRLF& _
;~ "[c=#FF0000]Moinsen,[/c] schwarz"&@CRLF
;~ _ChatBoxAdd($EditTailText,$data)
$aWndPos = WinGetPos($Form_znilTail)
WinMove($Form_znilTail, $sFormTitle, (@DesktopWidth - $aWndPos[2]) / 2, (@DesktopHeight - $aWndPos[3]) / 2, $aWndPos[2], $aWndPos[3])
; Were we startet with Commandline Parameter? #########################################################################
If $CmdLine[0] > 0 Then
$TailFile = $CmdLine[1]
If FileExists($TailFile) = 0 Then
MsgBox(262144,"znilTail: File not found!","znilTail.exe was startet with a File as Commandline Parameter:" & @CRLF & _
@CRLF & $TailFile & @CRLF & @CRLF & "but the File did not exist!",10)
Else
AdlibRegister("_TailFile", 1200)
GUICtrlSetState($ButtonStart, $GUI_DISABLE)
GUICtrlSetState($ButtonStop, $GUI_ENABLE)
GUICtrlSetState($ButtonOpen, $GUI_DISABLE)
$sFormTitle = "znilTail: " & $TailFile
_WinAPI_SetWindowText($Form_znilTail, $sFormTitle)
EndIf
EndIf
; Is Zabbix the Zabbix Agent installed on this Computer? If yes: Name of Service and Path+Filename of his Config-File?
$sRegSubKey = RegRead($aRegistryBaseServicePaths[0] & "Control", "CurrentUser")
If $sRegSubKey = "" Then
$sRegSubKey = RegRead($aRegistryBaseServicePaths[1] & "Control", "CurrentUser")
If $sRegSubKey = "" Then
$sRegSubKey = RegRead($aRegistryBaseServicePaths[2] & "Control", "CurrentUser")
If $sRegSubKey = "" Then
$iRightRegistryPath = 99
Else
$iRightRegistryPath = 2
EndIf
Else
$iRightRegistryPath = 1
EndIf
Else
$iRightRegistryPath = 0
EndIf
$i = 0
$zabbixAgentName = ""
$zabbixAgentConfigFile = ""
While 1
$i = $i + 1
$sRegSubKey = RegEnumKey($aRegistryBaseServicePaths[$iRightRegistryPath] & "services", $i)
If @error <> 0 Then ExitLoop
If StringLeft($sRegSubKey,StringLen("Zabbix Agent")) = "Zabbix Agent" Then
$zabbixAgentName = RegRead($aRegistryBaseServicePaths[$iRightRegistryPath] & "services\" & $sRegSubKey, "DisplayName")
$zabbixAgentConfigFile = RegRead($aRegistryBaseServicePaths[$iRightRegistryPath] & "services\" & $sRegSubKey, "ImagePath")
;"C:\Program Files\Zabbix\zabbix_agentd.exe" --config "c:\Program Files\Zabbix\zabbix_agentd.win.conf" -m
$zabbixAgentConfigFile = StringRegExpReplace($zabbixAgentConfigFile, '.*(?i)--config "', "")
$zabbixAgentConfigFile = StringRegExpReplace($zabbixAgentConfigFile, '".*', "")
ExitLoop
EndIf
WEnd
If $zabbixAgentConfigFile <> "" And FileExists($zabbixAgentConfigFile) = 1 Then
$bShowZabbixAgentButtons = True
Else
$bShowZabbixAgentButtons = False
EndIf
If IsAdmin() = 1 Then
$bAdminrights = True
;MsgBox(0,"","Admin Rechte!")
Else
$bAdminrights = False
;MsgBox(0,"","Du darfst nichts")
EndIf
;MsgBox(0,"$zabbixAgentConfigFile",$zabbixAgentConfigFile)
If StringLen($zabbixAgentConfigFile) > 0 And $bAdminrights = False Then
GUICtrlSetState($ButtonDebugLevel3, $GUI_DISABLE)
GUICtrlSetState($ButtonDebugLevel4, $GUI_DISABLE)
EndIf
;~ If $bAdminrights = True Then
;~ MsgBox(0,"","Adminrechte!")
;~ Else
;~ MsgBox(0,"","Keine Rechte")
;~ EndIf
If StringLen($zabbixAgentConfigFile) > 0 Then
If IsAdmin() = 1 Then
$hzabbixAgentConfigFile = FileOpen($zabbixAgentConfigFile, 0)
While 1
$stemp = FileReadLine($hzabbixAgentConfigFile)
If @error = -1 Then ExitLoop
If StringInStr($stemp,"DebugLevel") > 0 And StringInStr($stemp,"#") = 0 Then
$iCurrentDebugLevel = Int(StringRegExpReplace($stemp,"[.\s]*[^0-9]", ""))
;MsgBox(0,"DebugLevel",$iCurrentDebugLevel)
ExitLoop
EndIf
WEnd
FileClose($hzabbixAgentConfigFile)
EndIf
EndIf
;MsgBox(0,"$iCurrentDebugLevel",$iCurrentDebugLevel)
If $iCurrentDebugLevel = 3 Then
GUICtrlSetState($ButtonDebugLevel3, $GUI_DISABLE)
GUICtrlSetData($ButtonDebugLevel3, "Debug Level 3 is active")
GUICtrlSetState($ButtonDebugLevel4, $GUI_ENABLE)
GUICtrlSetData($ButtonDebugLevel4, "Restart Zabbix Agent with DebugLevel 4")
ElseIf $iCurrentDebugLevel = 4 Then
GUICtrlSetState($ButtonDebugLevel4, $GUI_DISABLE)
GUICtrlSetData($ButtonDebugLevel4, "Debug Level 4 is active")
GUICtrlSetState($ButtonDebugLevel3, $GUI_ENABLE)
GUICtrlSetData($ButtonDebugLevel3, "Restart Zabbix Agent with DebugLevel 3")
ElseIf $iCurrentDebugLevel >= 0 And $iCurrentDebugLevel < 3 Then
GUICtrlSetState($ButtonDebugLevel3, $GUI_ENABLE)
GUICtrlSetData($ButtonDebugLevel3, "Restart Zabbix Agent with DebugLevel 3")
GUICtrlSetState($ButtonDebugLevel4, $GUI_ENABLE)
GUICtrlSetData($ButtonDebugLevel4, "Restart Zabbix Agent with DebugLevel 4")
EndIf
If $zabbixAgentConfigFile = "" Then
GUICtrlSetTip($ButtonDebugLevel3, "Unavailable - no Zabbix Agent Service found on this Computer." & @CRLF & _
"znilTail.exe has looked for Agent in the Registry but found nothing.")
GUICtrlSetData($ButtonDebugLevel3, "No installed Zabbix Agent found!")
GUICtrlSetTip($ButtonDebugLevel4, "Unavailable - no Zabbix Agent Service found on this Computer." & @CRLF & _
"znilTail.exe has looked for Agent in the Registry but found nothing.")
GUICtrlSetData($ButtonDebugLevel4, "No installed Zabbix Agent found!")
GUICtrlSetTip($ButtonRestartAgent, "Unavailable - no Zabbix Agent Service found on this Computer." & @CRLF & _
"znilTail.exe has looked for Agent in the Registry but found nothing.")
GUICtrlSetData($ButtonRestartAgent, "No Zabbix Agent found!")
GUICtrlSetState($ButtonDebugLevel3, $GUI_DISABLE)
GUICtrlSetState($ButtonDebugLevel4, $GUI_DISABLE)
GUICtrlSetState($ButtonRestartAgent, $GUI_DISABLE)
Else
$iCurrentDebugLevel = _GetDebugLevel()
If $iCurrentDebugLevel = 4 Then
GUICtrlSetState($ButtonDebugLevel4, $GUI_DISABLE)
GUICtrlSetData($ButtonDebugLevel4, "Debug Level 4 is active")
GUICtrlSetState($ButtonDebugLevel3, $GUI_ENABLE)
GUICtrlSetData($ButtonDebugLevel3, "Restart Zabbix Agent with DebugLevel 3")
EndIf
EndIf
$hControl = ControlGetHandle($Form_znilTail, '', ControlGetFocus($Form_znilTail))
#EndRegion --- StartUp ------------------------------
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WinAPI_SetFocus($hControl)
_ChatBoxDestroy($EditTailText)
AdlibUnRegister("_TailFile")
GUIDelete($Form_znilTail)
Sleep(250)
Exit 0
Case $ButtonOpen
$TailFile = FileOpenDialog("Open File for Tail", @ScriptDir, "Textfiles (*.*)", 3, "", $Form_znilTail)
If $TailFile = "" Or @error = 1 Then
$TailFile = ""
$sFormTitle = "znilTail: No File selected"
Else
$sFormTitle = "znilTail: " & $TailFile
EndIf
_WinAPI_SetWindowText($Form_znilTail, $sFormTitle)
_WinAPI_SetFocus($hControl)
Case $ButtonStart
If $TailFile <> "" Then
AdlibRegister("_TailFile", 1200)
GUICtrlSetState($ButtonStart, $GUI_DISABLE)
GUICtrlSetState($ButtonStop, $GUI_ENABLE)
GUICtrlSetState($ButtonOpen, $GUI_DISABLE)
Else
MsgBox(262192,"znilTail: No file selected","You need to open a File first!",5)
EndIf
_WinAPI_SetFocus($hControl)
Case $ButtonStop
AdlibUnRegister("_TailFile")
GUICtrlSetState($ButtonStart, $GUI_ENABLE)
GUICtrlSetState($ButtonOpen, $GUI_ENABLE)
GUICtrlSetState($ButtonStop, $GUI_DISABLE)
_WinAPI_SetFocus($hControl)
Case $ButtonFontMinus
;_GUICtrlRichEdit_ChangeFontSize($EditTailText, -1)
If $iFontsize > 6 Then
$iFontsize = $iFontsize - 1
_GUICtrlRichEdit_SetFont($EditTailText, $iFontsize, "Courier New")
EndIf
_WinAPI_SetFocus($hControl)
Case $ButtonFontPlus
;_GUICtrlRichEdit_ChangeFontSize($EditTailText, 1)
$iFontsize = $iFontsize + 1
_GUICtrlRichEdit_SetFont($EditTailText, $iFontsize, "Courier New")
_WinAPI_SetFocus($hControl)
Case $ButtonHelp
_znilTailAboutBox()
_WinAPI_SetFocus($hControl)
Case $ButtonDebugLevel3
$iCurrentDebugLevel = 3
_WinAPI_SetFocus($hControl)
GUICtrlSetState($ButtonDebugLevel3, $GUI_DISABLE)
GUICtrlSetData($ButtonDebugLevel3, "Debug Level 3 is active")
GUICtrlSetState($ButtonDebugLevel4, $GUI_ENABLE)
GUICtrlSetData($ButtonDebugLevel4, "Restart Zabbix Agent with DebugLevel 4")
_SetDebugLevelandRestartAgent($iCurrentDebugLevel)
Case $ButtonDebugLevel4
$iCurrentDebugLevel = 4
_WinAPI_SetFocus($hControl)
GUICtrlSetState($ButtonDebugLevel4, $GUI_DISABLE)
GUICtrlSetData($ButtonDebugLevel4, "Debug Level 4 is active")
GUICtrlSetState($ButtonDebugLevel3, $GUI_ENABLE)
GUICtrlSetData($ButtonDebugLevel3, "Restart Zabbix Agent with DebugLevel 3")
_SetDebugLevelandRestartAgent($iCurrentDebugLevel)
Case $ButtonRestartAgent
_WinAPI_SetFocus($hControl)
$i = Run(@ComSpec & ' /c net stop "' & $zabbixAgentName & '"', "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
$iTimer = TimerInit()
While ProcessExists("zabbix_agentd.exe") > 0
Sleep(100)
If TimerDiff($iTimer) > 10000 Then
ExitLoop
EndIf
WEnd
;Sleep(2000)
$i = Run(@ComSpec & ' /c net start "' & $zabbixAgentName & '"', "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
Case $GUI_EVENT_RESIZED
_WinAPI_SetFocus($hControl)
GUISetState(@SW_HIDE,$Form_znilTail) ;Hide GUI
GUISetState(@SW_SHOW,$Form_znilTail) ;Show GUI
Case $GUI_EVENT_MAXIMIZE
_WinAPI_SetFocus($hControl)
GUISetState(@SW_HIDE,$Form_znilTail) ;Hide GUI
GUISetState(@SW_SHOW,$Form_znilTail) ;Show GUI
Case $GUI_EVENT_RESTORE
_WinAPI_SetFocus($hControl)
GUISetState(@SW_HIDE,$Form_znilTail) ;Hide GUI
GUISetState(@SW_SHOW,$Form_znilTail) ;Show GUI
;~ Case -7
;~ GUISetState(@SW_HIDE,$Form_znilTail) ;Hide GUI
;~ GUISetState(@SW_SHOW,$Form_znilTail) ;Show GUI
;~ Case $InputHighlightText
;~ If GUICtrlRead($InputHighlightText) = "Highlight Lines with this Text" Then
;~ GUICtrlSetData($InputHighlightText, "")
;~ GUICtrlSetData($CheckboxHighlight, $GUI_CHECKED)
;~ EndIf
EndSwitch
If ControlGetHandle($Form_znilTail, '', $InputHighlightText) = ControlGetHandle($Form_znilTail, '', ControlGetFocus($Form_znilTail)) Then
If GUICtrlRead($InputHighlightText) = "Highlight Lines with this Text" Then
GUICtrlSetData($InputHighlightText, "")
GUICtrlSetState($CheckboxHighlight, $GUI_CHECKED)
EndIf
EndIf
If ControlGetHandle($Form_znilTail, '', $InputHidetext) = ControlGetHandle($Form_znilTail, '', ControlGetFocus($Form_znilTail)) Then
If GUICtrlRead($InputHidetext) = "Hide Lines with this Text" Then
GUICtrlSetData($InputHidetext, "")
GUICtrlSetState($CheckboxHideText, $GUI_CHECKED)
EndIf
EndIf
If GUICtrlRead($CheckboxHighlight) = $GUI_CHECKED Then
$bUseColorize = True
Else
$bUseColorize = False
EndIf
If GUICtrlRead($CheckboxHideText) = $GUI_CHECKED Then
$bHideText = True
Else
$bHideText = False
EndIf
WEnd