
Nagios – Checking the Time on Windows Machines
If we want to check the time we have between a Windows machine and the time that its Active Directory has, This is your document! We will be able to check with the following script the time difference in milliseconds that we have, is super useful to check a service as critical as the Time, and that all our machines have it perfectly synchronized!
In principle we will base ourselves on the following script 'check_ad_time.vbs', a Visual Basic script that we can easily execute remotely with NRPE, You can download it from here: https://exchange.nagios.org/directory/Plugins/Operating-Systems/Windows-NRPE/check_ad_time-2Evbs/details
But in my case I had to modify this script because on Windows machines in Spanish it gave me problems and it really did not work, I'll leave it in this link in case you prefer to download this corrected file. What I said, we can use this simple script to check the time difference between a Windows machine against a domain controller or directly against an NTP time server either internal or public. We will run it remotely using NRPE, therefore, if you haven't followed previously said document, I recommend you read it!
Download check_ad_time.vbs, usually in the 'C directory:\Program FilesNSClient++scripts', We edit the file 'nsclient.ini’ to add the following settings, where we will define the alias and then the script that will execute. Call the vbs and pass you 2 Arguments, the first is what you check it against and the second is the maximum time difference, will look at the offset in seconds. We can test it first from a CMD, If we want to clear!
[SourceCode][/settings/external scripts/scripts]
time = cscript.exe //T:30 //NoLogo scriptscheck_ad_time.vbs $ARG 1$ "$ARG 2$"
[/settings/external scripts/alias]
Time = Time[/SourceCode]
Save the file and restart the NSClient service ++.
And nothing, from Centreon, we must create the Service that will monitor this and relate it to the Host where it will run, which should be all the Windows machines that we are interested in. “Configuration” > “Services” > “Add…” or as always, the most convenient thing to do is to duplicate an existing one that is similar. We configure at least the following service options:
- Description: We indicate the name with which we will see you from the monitoring, I call it for example 'Sync Hora'.
- Linked with Hosts: What I said, the computers where we will run that VBS script to monitor.
- Template: Normally, Select 'generic-active-service-custom'.
- Check Command: Select from the list of commands, 'check_nrpe'.
- Args: Pass the alias of the script that will execute followed by the arguments. In my case it would be something like 'time -a domain.lan 0.01’
We keep with “Save”,
And well, after saving, Export and reload settings, As we are tired of doing it… 😉 It will be enough to just go to the monitoring view and check that this check that we have just generated works for us! “Monitoring” > “Status details” and filter the view by the Host or the Service and we will see after a few minutes that it runs perfectly! With this we already have something as fundamental as the fully controlled time service on our machines, We will find out about any delay avoiding possible service failures in our business!