Monitoring the status of Domain Controller Diagnostics Tool (dcdiag.exe) with Nagios XI

I was recently looking at monitoring the service health of Active Directory Domain Services using Nagios XI, the default monitoring wizards only provide the ability to monitor an LDAP server. However, I was looking to monitor a number of services similar to those available from running the Domain Contoller Diagnostics Tool (dcdiag.exe) –

Therefore, I decided to create a powershell script that would allow for the state of a domain controller to be analysed and for a service status to be returned using the check_nrpe command.

I wanted my powershell script to be flexible enough to run a test agaisnt a single service on a domain controller, so I specified a mandatory parameter for the test name required to be run.


I will also be required to generate a string for the timestamp to include in the status information message on when the service check was last performed.



As previously stated I will be using the dcdiag.exe utility to run a specific test which has been specified in the mandatory parameter to which I will capture the output to a filter.



Once the test has completed and the output has been captured I will use conditional logic to determine the service status, return a service state and generate a status information message.









The powershell session will then exit returning the exit code.


Now that we have a powershell script to monitor the service health, we need to add this to the external scripts section of the NSClient++ configuration file (C:\Program Files\NSClient++\NSC.ini) and copy the powershell script to the scripts folder so that the client service may invoke the command ((C:\Program Files\NSClient++\scripts).

[External Scripts]
check_directoryservergiagnostics= cmd /c echo scripts\Check-DirectoryServerDiagnostics.ps1 -Test $ARG1$; exit($lastexitcode) | powershell.exe -command -

The final step is to create a service,  we need to use the check_nrpe command and set the $ARG1$ value as below in the example of running the DNS test (dcdiag /test:DNS) , save the service and apply the configuration.

check_directoryservergiagnostics -a "DNS"

Once you have applied the service to a host, or in my case the host group created for all my domain controllers, following the next service check you will receive a service status.


Once issue I had was that the DNS test can take a complete of minutes to complete and produce the output, therefore the default check_nrpe command settings are not applicable for this service to complete successfully as the check will timeout, I therefore used a copy of the check_nrpe command to which I had previously changed the timeout value to 600 seconds in order for the test to complete, see for more information on resolving the check_nrpe socket timeout issue:

While the script was created to be executed as an external script within Nagios, this can be run standalone from Windows Powershell.


The full Windows Powershell script can be downloaded from the below link:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s