How to Monitor Hyper-V Checkpoints with the Script Sensor
Discover how to configure NetCrunch to monitor Hyper-V checkpoints remotely and set up alerts based on the output.
Monitoring Hyper-V checkpoints is essential to ensuring that your virtual environment remains healthy and efficient. With NetCrunch, you can easily execute PowerShell scripts on any Windows machine, such as a Hyper-V host, and use the script results to generate alerts and take action when needed.
Why Use NetCrunch for PowerShell Script Execution?
NetCrunch allows you to automate the execution of PowerShell scripts across your network, leveraging its monitoring capabilities to run scripts on any Windows machine. This flexibility means you can monitor various metrics, including Hyper-V checkpoints, without logging into each machine manually. NetCrunch can execute scripts on remote computers, collect the output, and generate alerts based on predefined conditions, helping you to maintain optimal performance and security in your IT environment.
Step-by-Step Guide to Monitoring Hyper-V Checkpoints with NetCrunch
To monitor Hyper-V checkpoints with NetCrunch, ensure that the Hyper-V host allows remote PowerShell script execution from the NetCrunch server and that the Script Sensor is correctly configured to run the script.
Configure the Hyper-V Host to Accept Remote Scripts from the NetCrunch Server
To securely monitor Hyper-V checkpoints, the Hyper-V host must be configured to accept PowerShell commands remotely, specifically from the NetCrunch server:
1. Enable PowerShell Remoting:
On the Hyper-V host (the Windows machine running Hyper-V), open PowerShell as an administrator and run the following command to enable PowerShell Remoting:
powershell
Enable-PSRemoting -Force
This command configures the necessary settings and starts the WinRM service, allowing remote PowerShell commands to be executed.
2. Set Trusted Hosts to Allow Only NetCrunch Server:
Limit remote script execution to only the NetCrunch server by setting the WinRM TrustedHosts
list to include only the NetCrunch server's Fully Qualified Domain Name (FQDN).
On the Hyper-V host, run the following command in PowerShell:
powershell
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "netcrunch.example.local"
Replace netcrunch.example.local
with the actual FQDN of your NetCrunch server. This ensures that only the NetCrunch server can execute remote PowerShell scripts on the Hyper-V host.
3. Restart the WinRM Service:
After setting the trusted hosts, restart the WinRM service to apply the changes:
powershell
Restart-Service WinRM
4. Adjust Firewall Settings:
Ensure the firewall on the Hyper-V host allows incoming WinRM traffic only from the NetCrunch server - create a firewall rule that permits traffic from the NetCrunch server's IP address or FQDN.
You can use the Windows Defender Firewall with Advanced Security to create a custom rule:
- Open Windows Defender Firewall with Advanced Security.
- Navigate to Inbound Rules and click New Rule.
- Select Custom and click Next.
- Choose All programs and click Next.
- Select TCP and specify Local port as
5985
(HTTP) or5986
(HTTPS), then click Next. - Under Which remote IP addresses does this rule apply to?, select These IP addresses and add the IP address of the NetCrunch server.
- Complete the wizard to apply the rule.
2. Configure the NetCrunch Script Sensor
Once the Hyper-V host is configured to accept remote scripts only from the NetCrunch server, you need to set up the Script Sensor in NetCrunch to monitor the checkpoints.
Add a Script Sensor in NetCrunch:
Open the NetCrunch administration console and navigate to the node where you want to add the Script Sensor. Click on "Add Sensor" and select "Script Sensor".
Set Up the Script Sensor:
- Script Type: Choose “PowerShell” to indicate that the script to be executed is a PowerShell script.
- Script File: Provide the full path to the PowerShell script file on the NetCrunch server. Make sure this path is accessible and that the script has the necessary permissions to be executed.
- Pass Credentials Through PSCredential Object: Check this option to ensure the credentials required to execute the script remotely are securely passed to the PowerShell session.
- Credentials: Enter the credentials that have permission to execute the script on the Hyper-V host. These should be credentials with administrative access to the Hyper-V host to allow the script to retrieve checkpoint information.
- Script Output Data Format: Set this to “Auto-detect”. NetCrunch will automatically determine the format of the output returned by the script and process it accordingly.
- Save and Apply the Sensor Configuration
- Use the
Test
button to check the Sensor configuration - Save the configuration settings and apply them to the selected node. The Script Sensor will now be configured to remotely execute the PowerShell script on the Hyper-V host and collect the output.
3. Set Up Alerts Based on the Script Output
NetCrunch can use the script output to trigger alerts and actions. For example, you can set up an alert if the number of checkpoints older than 24 hours exceeds a certain threshold.
Configure Alerting:
- Click
Alert
- Select
New Event for Monitoring Sensor Counter
- Name Alert and choose Alert Severity
- in the Event Condition section choose
Select Counter
- Select the name of your counter and then click OK
- Select the value instead of average value and set trigger (e.g. >0)
- Select
reset conditions
and then click OK - Don't forget to assign Alerting Script
That's all. As a result, you will receive an alert if on the selected Hyper-V host anu Checkpoints older than 24h are detected.
Conclusion
By implementing the NetCrunch Script Sensor, you can automate the monitoring of Hyper-V checkpoints across your environment. This approach ensures that you have real-time visibility into the status of your checkpoints, allowing you to proactively manage your virtual infrastructure and prevent potential issues before they affect your operations. By configuring PowerShell Remoting to accept scripts only from the NetCrunch server, you maintain a secure monitoring setup, minimizing the risk of unauthorized script execution.