Introduction
In this article, we will discuss how to create a script that checks if a server has rebooted and sends an email notification using ManageEngine's Notification Manager.
Prerequisites
To follow this tutorial, you need to have the following:
- A server running the ManageEngine Operations Manager
- Knowledge of PowerShell or a similar scripting language
- Access to the ManageEngine Notification Manager
Step 1: Create a PowerShell Script
First, we need to create a PowerShell script that checks if the server has rebooted. Here's a simple example:
PowerShell Script
param (
[string]$serverName
)
$rebootTime = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $serverName).LastBootUpTime
$currentTime = Get-Date
$rebootDuration = New-TimeSpan -Start $rebootTime -End $currentTime
if ($rebootDuration.Days -gt 0) {
Write-Output "Server $serverName has rebooted $($rebootDuration.Days) days ago."
} elseif ($rebootDuration.Hours -gt 0) {
Write-Output "Server $serverName has rebooted $($rebootDuration.Hours) hours ago."
} elseif ($rebootDuration.Minutes -gt 0) {
Write-Output "Server $serverName has rebooted $($rebootDuration.Minutes) minutes ago."
} else {
Write-Output "Server $serverName has rebooted less than a minute ago."
}
Step 2: Schedule the PowerShell Script
Next, schedule the PowerShell script to run at regular intervals using the Task Scheduler.
Step 3: Create a ManageEngine Notification Profile
Now, we will create a Notification Profile in ManageEngine Notification Manager to send an email when the server reboots.
Notification Profile Configuration
- Name: Server Reboot Notification
- Event Type: Custom Event
- Event Name: ServerRebooted
- Email Notification: Enable
- Recipients: Specify the email addresses to receive the notifications
- Subject: Server $serverName has rebooted
- Message: Server $serverName has rebooted. More details can be found in the script output.
Step 4: Trigger the Notification
Finally, manually trigger the PowerShell script to test the notification. If the server has rebooted, you should receive an email notification.
In this article, we learned how to create a PowerShell script that checks if a server has rebooted and sends an email notification using ManageEngine's Notification Manager.
References
- ManageEngine Operations Manager Documentation: https://www.manageengine.com/products/opmanager/
- ManageEngine Notification Manager Documentation: https://www.manageengine.com/products/notification-manager/