Monday, September 13, 2010

Citrix or Terminal Techbyte!

Something or someone disables logons on your Citrix or Terminal server and logons never get enabled.

Now you have a server nobody can log into and you are clueless about it.

If you have Nagios working in your environment-Here is a solution to send alert.

Prerequist: Nagios, NRPE addon, Nagios Agent installed on Windows Server, and a program that can read Reg key and communicate with Nagios.
There is a Nagios utility out there created already, but it contains a serious bug that cannot read a value of Zero properly.

Working together, here is what our team came up with.
We created a custom utility with AutoIT and called tsnenable.exe

Here is the code:

;tsenable - purpose to read registry key for value to see if Terminal Services Logons are enabled 0 or disabled 1
;then based on that, it does either of these two things: 0, then write to console message and set exit code to 0
;else if 1, then write to the console, and set exit code to 1.
;This must be compiled as a non-gui application for it to work.
;This is to be used in conjunction with nagios

;Written by:
;September 1, 2010

dim $RegVal, $i

$RegVal=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "WinStationsDisabled")
If @error <> 0 Then
MsgBox(0, "oops", "Crap! This is not working!")
Exit
EndIf
if $RegVal = 0 then
ConsoleWrite("Logons Enabled")
Exit(0)
Else
ConsoleWrite("Logons Disabled")
Exit(1)
EndIf

Note: You must compile this as a Command Line Interface not GUI!

Now the actual steps:

1. Install newer nsclient on Citrix server. If you have old client, uninstall that one first then install nsclient_3.6RC8 and get it working with Nagios.

2. Create a folder called nsscripts put the custom app in that folder.

3. Put nsscripts in the NSclient++ program files folder.

4. Rename nsc.ini in NSClient++ to nsc.ini.org

5. Edit nsc.ini in the NSclient++ folder. I am only going to cover the part for running custom scripts.

[External Script]
.
.
.
.
.
; *********** CREATED THIS FOLDER IN THE NSCLIENT++ FOLDER *********
script_dir=.\nsscripts\*.exe

[NRPE Handlers]
.
.
.
.
.
; *********** Custom app **********
check_tslogon=nsscripts\tsenable.exe

6. Reastart Service for nsclient.

7. Create nagios service entry in services.cfg
This is Linux so you have to use vi or nano editor:

vi services.cfg

NOTE: service_description below uses "check_command" from nrpe2 which calls the tsenable.exe.
In the INI file above notice the "check_tslogon" setting pointing to the custom tsenable.exe.

# Service definition
define service{
use generic-service ; Name of service template to use

host_name CITRIX1
service_description TS Logons
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups citrix-admins
notification_interval 360
notification_period awakehours
notification_options w,u,c,r
check_command check_nrpe2!check_tslogon

8. Restart Nagios.

Delco

No comments: