Save to My DOJO
Table of contents
This script will be required for other scripts that will focus on cluster functionality. It is presented separately from the Hyper-V scripts because its commands will only be useful in a cluster environment. Many of them do not even require Hyper-V to be installed on the nodes. Like the Hyper-V scripts, you must have NSClient++ installed on all of the nodes.
Check out this comprehensive introduction to Nagios prepared by Eric if you want to get started with the free monitoring tool – you’ll find three additional scripts to get you started with Nagios in Hyper-V. You can also check out Nagios for Hyper-V: Alert on Low Cluster Shared Volume Space which follows up on this article.
Last updated: May 17, 2017 to 1.1.1. Important! You must update the other base files as well!
Nagios Configuration Files
Start with the configuration file changes as listed on the Hyper-V base scripts article. If you are only interested in the cluster scripts and not any of the Hyper-V scripts, you must still make all of these changes as shown in that article:
- Uncomment the Windows.cfg line in nagios.cfg
- Add a “host” entry to one of the .cfg files to represent the cluster(s) that you want to monitor. In the Hyper-V base scripts article, you’ll find an example in the hypervhost.cfg listing
- Create an entry for a cluster object in templates.cfg. In the Hyper-V base scripts article, it is referred to as a Hyper-V host, but you can change that to anything that suits you.
The remaining configuration file to change is the commands file, where you will enter all of the cluster commands alongside the others.
/usr/local/nagios/etc/objects/commands.cfg
You can use a different name for the grouping if it suits your environment. The actual command shown in the following section is just an example. For the actual command, please refer to the article that includes the entire script package.
################################################################################ # # Cluster Commands # ################################################################################ # check-csv-freespace # $ARG1$: the name of the CSV to monitor # $ARG2$: percentage of free space that will trigger a warning # $ARG3#: percentage of free space that will trigger a critical alert define command{ command_name check-csv-freespace command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -p 5666 -c check_csvfreespace -a $ARG1$ $ARG2$ $ARG3$ }
NSClient++ Configuration
There are some general notes in the base Hyper-V scripts article that are all applicable here. The primary point that bears repeating is that the host must have its execution policy lowered to at RemoteSigned at the highest. 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:
[/settings/external scripts] allow arguments = true [/settings/external scripts/wrappings] ps1=cmd /c echo scripts\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -noprofile -nologo -command - [/settings/external scripts/wrapped scripts] check_csvspace=check_csvspace.ps1 $ARG1$ $ARG2$ $ARG3$
C:\Program Files\NSClient++\scripts\clusterbase.ps1
<# clusterbase.ps1 Written by Eric Siron (c) Altaro Software 2017 Version 1.1.1 May 17, 2017 Intended for use with the NSClient++ module from http://nsclient.org Provides reusable functions for other check scripts. #> if(-not $ClusterBaseIncluded) { $ClusterBaseIncluded $UtilityBase = Join-Path -Path $PSScriptRoot -ChildPath 'anutilitybase.ps1' if(-not (Test-Path -Path $UtilityBase)) { Write-Host ('Required file {0} not found' -f $UtilityBase) exit 3 } . $UtilityBase function Get-ANClusterBaseVersion { New-Object System.Version(1, 1, 1, 0) } function Get-ANIsClustered { [bool](Get-WmiObject -Namespace root -Class '__NAMESPACE' -Filter 'Name="MSCluster"') } Set-Alias -Name ANIsClustered -Value Get-ANIsClustered function Get-ANClusterPartitionFromCSVName { param( [Parameter()][String]$CSVName ) Get-CimInstance -Namespace root\MSCluster -Class MSCluster_DiskPartition -Filter ('FileSystem="CSVFS" AND VolumeLabel="{0}"' -f $CSVName) } function Get-ANCSVFromCSVName { param( [Parameter()][String]$CSVName ) $CSVDiskPartition = Get-ANClusterPartitionFromCSVName -CSVName $CSVName if($CSVName) { Get-CimInstance -Namespace root\MSCluster -Class MSCluster_ClusterSharedVolume -Filter ('VolumeName="{0}"' -f ($CSVDiskPartition.Path -replace '\\', '\\')) } } function Get-ANClusterNodes { (Get-WmiObject -Namespace root\MSCluster -Class MSCluster_Node).Name } }
Further check scripts will be published on this blog that utilize the above.
Not a DOJO Member yet?
Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!
2 thoughts on "Nagios for Hyper-V: Required Cluster Base Script"
Hi, where can we found anutilitybase.ps1 ?
https://www.altaro.com/hyper-v/nagios-for-hyper-v-required-base-scripts/