Nagios for Hyper-V: Required Base Scripts

To use this article, you will need to have a functioning Nagios environment with the CHECK_NRPE plugin. Your Hyper-V hosts will need to have NSClient++ installed. Both will need to have the configuration as explained near the end of my Nagios configuration article.

Update History

  • May 24th, 2017
    • Updated hvdiskbase.ps1 to version 1.2. Corrects sporadic issues for cluster VMs introduced in 1.1. Depends on hvvmbase 1.0.2
    • Updated hvvmbase.ps1 to version 1.0.2. Adds resilience to cluster VM location
  • May 23rd, 2017
    • Updated hvdiskbase.ps1 to version 1.1.1. Minor changes to improve dependent script error controls.
  • May 21st, 2017
    • Updated hvdiskbase.ps1 to version 1.1. Breaking change: This updates the Get-ANVMDisk function so that it works with offline as well as online virtual machines. It does not affect the scripts published on this site.
  • May 17th, 2017
    • Updated hvvmbase.ps1 to version 1.0.1
    • Updated hvdiskbase.ps1 to version 1.0.1
    • Added anutilitybase.ps1

Nagios Configuration Files

This section shows changes and additions that must be made to the Nagios configuration files.

Modify the displayed portion of these files with the highlighted section. If nothing is highlighted, then just add it to the bottom.

Important notes:

  1. Do not forget to swap out my host and object names for your own!
  2. Do not forget to use ‘service nagios checkconfig’ before trying to apply ANY changes.

After the configuration changes are complete, use  service nagios restart  on the Nagios system to apply them.


Notice that you must uncomment the windows.cfg line.


The backing scripts for the commands listed below will appear in other articles. These are examples of how they will be entered. If you have a method that fits your environment more efficiently, use it.



This file doesn’t exist — you’ll have to create it. If you do not have a Hyper-V cluster, ignore those sections.


This addition is only necessary if you will be monitoring a Hyper-V cluster.

NSClient++ Configuration

The additions and changes in this section are made on Hyper-V hosts that are running NSClient++. No checks are included in this article. These scripts are required for scripts that I’ll present in other articles.

All scripts have been tested with PowerShell version 4.0. There is no known reason why they would not work with PowerShell 5.0 or later.

A Note on the PowerShell Scripts

When I share scripts with you, it is with the genuine hope that they’ll be useful. I certainly don’t mind if you pick them apart for learning, for improving, for bug hunting, or pretty much anything that doesn’t involve stealing my work to claim as your own. If you look at these scripts, you will see many, many, many places where I could have used a completely different cmdlet and saved myself lots of trouble and several lines of script. You’ll also notice that I used almost zero comments. I promise you that I did not intentionally make these scripts difficult to read. These scripts are going to be executed frequently on every host where they reside. I also have no idea what you have or have not done in your environment. Therefore, I rigidly adhered to two goals when designing these scripts:

  • Reduction of non-essential information. This mostly meant, “very few comments”. I don’t know how much it really saves, but I tend to write almost as many comment lines as script lines so it seemed possible that forcing the PowerShell interpreter to examine and ignore dozens of comment lines would become a drag in aggregate. I avoided positional parameters and aliases because I did not feel that the readability trade-off was worth the effort when I was also avoiding comments and also because I assume that PowerShell burns up CPU cycles figuring out positional parameters and aliases just like people do.
  • No assumptions of the presence of any PowerShell modules except what is in the base package. If any of my Nagios scripts call a cmdlet that doesn’t exist, either you didn’t copy everything that I told you to or your PowerShell installation is damaged. I did not use common Hyper-V or Failover Clustering cmdlets because I cannot be certain that Get-VM will work on a Hyper-V host or that Get-ClusterResource will work on a failover cluster member because their PowerShell modules are optional. Additionally, I assume that not requiring PowerShell to load up or hook into those DLLs or follow the deeper logic trails that Microsoft used in those cmdlets should speed up processing to some degree.

I did attempt to make the scripts as legible as possible while following those goals.

Remember that every host must have its execution policy set to RemoteSigned or something less restrictive. You can run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned.

C:\Program Files\NSClient++\nsclient.ini

The base Nagios article includes a section on configuring the ini file correctly. The portion that establishes PowerShell functionality and a couple of samples for checks are shown below:

C:\Program Files\NSClient++\scripts\hvvmbase.ps1

This script contains some general-purpose and virtual machine-related functions that will be used by my other scripts that perform Hyper-V host checks. This file does not exist and must be created.


C:\Program Files\NSClient++\scripts\hvdiskbase.ps1

This script contains functions that will be used by my other scripts that work with Hyper-V virtual hard disks. This file does not exist and must be created.

C:\Program Files\NSClient++\scripts\anutilitybase.ps1

This script contains functions that will be used by my other scripts. Most will not work without it. This file does not exist and must be created.



Backing up your Hyper-V VMs

If you’d like to make backing up your Hyper-V VMs easy, fast and reliable, check out Altaro VM Backup. It’s free for up to 2 VMs, packed with features and the most affordable backup solution for SMBs around. Download a 30-day trial OR the Free version at and get started in under 15 minutes.

Get notified about ​new articles by email

Receive all our free Hyper-V articles and checklists and get notified first when we release new eBooks and announce upcoming webinars!

Share This