Created
May 16, 2014 10:08
-
-
Save LKLG/3d11e7a86f22702b706a to your computer and use it in GitHub Desktop.
AutoIT-Script with automatic XenApp-logontime and Nagios reporting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** | |
#AutoIt3Wrapper_Icon=lklgdesktop.ico | |
#AutoIt3Wrapper_Outfile=check_login_time_receiver.exe | |
#AutoIt3Wrapper_Change2CUI=y | |
#AutoIt3Wrapper_Res_Fileversion=0.0.0.26 | |
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y | |
#AutoIt3Wrapper_Res_Language=1031 | |
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** | |
#include <Constants.au3> | |
#include <array.au3> | |
#include <myImageSearch.au3> | |
; Variablendeklaration | |
Global $button1 = @ScriptDir & "\windowsstart3.bmp" | |
Global $button2 = @ScriptDir & "\windowsstart2.bmp" | |
Global $nagwarn = 20 | |
Global $nagcrit = 60 | |
Global $timeout = 120 | |
if ($CmdLine) Then | |
$nagwarn = $Cmdline[1] | |
$nagcrit = $Cmdline[2] | |
$timeout = $Cmdline[3] | |
EndIf | |
Func ExecuteNscp ($erg,$rcode) | |
ShellExecute('C:\Program Files\NSClient++\nscp.exe', 'nsca -H icinga01.lklg.net -P 5667 -e submit -m "' & $erg & '" -r ' & $rcode & ' --source-host checkhost -c login_time') | |
EndFunc | |
Func Res($durationica) | |
$strend = "- " & $durationica & " Sekunden | Anmeldedauer=" & $durationica & ";" & $nagwarn & ";" & $nagcrit & ";0;300" | |
If $durationica > $nagcrit And $durationica > $nagwarn Then | |
$erg = "critical " & $strend | |
$rcode = 2 | |
ElseIf $durationica > $nagwarn And $durationica < $nagcrit Then | |
$erg = "warning " & $strend | |
$rcode = 1 | |
Else | |
$erg = "ok " & $strend | |
$rcode = 0 | |
EndIf | |
ExecuteNscp($erg,$rcode) | |
EndFunc | |
Func GetLoginTime () | |
;Opt("WinTitleMatchMode", 4) | |
Local $dauerica | |
Local $startica | |
; Start Citrix Receiver | |
ConsoleWrite("starting receiver" & @CRLF) | |
Run("C:\Users\it-service\AppData\Roaming\Citrix\SelfService\LKLGDesktop.exe") | |
; Activate Citrix Receiver and Wait for it | |
ConsoleWrite("waiting for receiver window" & @CRLF) | |
If WinWait("[TITLE:LKLG Desktop - Desktop Viewer]","",$timeout) Then | |
ConsoleWrite("activating receiver window" & @CRLF) | |
WinActivate("[TITLE:LKLG Desktop - Desktop Viewer]") | |
ConsoleWrite("searching start menu" & @CRLF) | |
$startica = TimerInit() | |
; Start Searching | |
While True | |
$Number0 = _ImageSearch_Position($button1,"topleft",210,420) | |
$Number1 = _ImageSearch_Position($button2,"topleft",210,420) | |
$dauerica = TimerDiff($startica) | |
$dauerica = Round(($dauerica / 1000), 1) | |
; If Picture Found | |
If IsArray($Number0) Then | |
; Goto Startbutton | |
ConsoleWrite("image found, moving the mouse" & @CRLF) | |
MouseMove($Number0[0]+2,$Number0[1]+2) | |
ExitLoop | |
ElseIf IsArray($Number1) Then | |
ConsoleWrite("image found, moving the mouse" & @CRLF) | |
MouseMove($Number1[0]+2,$Number1[1]+2) | |
ExitLoop | |
Else | |
ConsoleWrite("image not found after " & $dauerica & " sec" & @CRLF) | |
If ($dauerica > $timeout) Then | |
ConsoleWrite("timeout" & @CRLF & "closing receiver window" & @CRLF) | |
;close receiver window, report critical | |
WinClose("[TITLE:LKLG Desktop - Desktop Viewer]") | |
ConsoleWrite("sending result to icinga" & @CRLF) | |
ExecuteNscp("critical - timeout reached ("& $timeout & " s) | Anmeldedauer="& $dauerica &";" & $nagwarn & ";" & $nagcrit & ";0;300",2) | |
return | |
EndIf | |
EndIf | |
WEnd | |
WinActivate("[TITLE:LKLG Desktop - Desktop Viewer]") | |
; Click on Startbutton | |
;ConsoleWrite("klicking the start button" & @CRLF) | |
;MouseClick("left") | |
ConsoleWrite("waiting 5 sec (logoff script must start in session)" & @CRLF) | |
Sleep(5000) | |
; Logoff | |
ConsoleWrite("logging off" & @CRLF) | |
Send("{ENTER}") | |
;Send("{Tab 2}{ENTER}") | |
; Wait until Citrix Receiver not exists | |
ConsoleWrite("waiting till the window is closed" & @CRLF) | |
If Not WinWaitClose("[TITLE:LKLG Desktop - Desktop Viewer]","",$timeout) Then | |
ConsoleWrite("force close window" & @CRLF) | |
WinKill("[TITLE:LKLG Desktop - Desktop Viewer]") | |
EndIf | |
; Send Result to Icinga | |
ConsoleWrite("sending results to icinga" & @CRLF) | |
Res($dauerica) | |
Return | |
Else | |
Sleep(1000) | |
Send("!{PRINTSCREEN}") | |
ConsoleWrite("unknown error | screenshot taken" & @CRLF) | |
If WinExists("[TITLE:Citrix Receiver]") Then | |
WinKill("[TITLE:Citrix Receiver]") | |
EndIf | |
IF WinExists("[TITLE:LKLG Desktop - Desktop Viewer]") Then | |
WinKill("[TITLE:LKLG Desktop - Desktop Viewer]") | |
EndIf | |
ExecuteNscp("critical - unknown problem | Anmeldedauer=0;" & $nagwarn & ";" & $nagcrit & ";0;300",2) | |
Return | |
EndIf | |
EndFunc | |
While True | |
ConsoleWrite("start check" & @CRLF) | |
GetLoginTime() | |
; Repeat all 5 Min | |
ConsoleWrite("waiting 5 minutes" & @CRLF) | |
Sleep(300000) | |
;Sleep(60000) | |
WEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Datenlizenz Deutschland – Namensnennung – Version 1.0 | |
Jede Nutzung mit Quellenvermerk ist zulässig. | |
Veränderungen, Bearbeitungen, neue Gestaltungen oder sonstige Abwandlungen sind mit einem Veränderungshinweis im Quellenvermerk zu versehen oder der Quellenvermerk ist zu löschen, sofern die datenhaltende Stelle dies verlangt. | |
Der Bereitsteller stellt die Daten, Inhalte und Dienste mit der zur Erfüllung seiner öffentlichen Aufgaben erforderlichen Sorgfalt zur Verfügung. Für die Daten, Inhalte und Dienste gelten in Bezug auf deren Verfügbarkeit und deren Qualität die durch den Bereitsteller in den Metadaten oder sonstigen Beschreibungen zugewiesenen Spezifikationen und Qualitätsmerkmale. Der Bereitsteller übernimmt jedoch keine Gewähr für die Richtigkeit und Vollständigkeit der Daten und Inhalte sowie die dauerhafte Verfügbarkeit der Dienste. Davon ausgenommen sind Schadensersatzansprüche aufgrund einer Verletzung des Lebens, körperliche Unversehrtheit oder Gesundheit. Ebenfalls ausgenommen sind Schäden, die auf Vorsatz oder grober Fahrlässigkeit beruhen. | |
Data licence Germany – attribution – Version 1.0 | |
Any use shall be permitted provided the source is mentioned. | |
Changes, editing, new designs or other amendments shall be marked with information in the source note about relevant changes, or the source note must be deleted if the entity keeping the data requires so. | |
The provider makes available the data, contents and services with the diligence necessary for the discharge of its public tasks. With reference to their availability and quality, the specifications and quality features assigned by the provider in the meta-data or other descriptions apply to the data, contents and services. However, the provider does not assume any liability for the accuracy and completeness of data and contents and for permanent availability of services. Exempt from this are any claims for damage due to an injury to life, limb or health. Also exempt is damage based on wilfulness or gross negligence. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- NSCP-Client: http://sourceforge.net/projects/nscplus/ | |
- myImageSearch: The myImageSearch.au3 can be found here -> http://www.autoitscript.com/forum/topic/134390-myimagesearch/?hl=%2Bmyimagesearch#entry1092745 | |
- Constants: The Constants.au3 can be found in a standard AutoIT-installation. (http://www.autoitscript.com/site/) | |
- array: The array.au3 can be found in a standard AutoIT-installation. (http://www.autoitscript.com/site/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment