Question

NLB Info
Load Balancer: LoadBal
NODE 1
NODE 2

I want to receive emails whenever a node is not acting as a load balancing server. I have a scheduled task that runs the following script continuously. THis script emails me when a node is not acting as a load balancing server.

My test scenarios:

Scenario 1:
Stopping Node 1 from the NLB but I didn't receive an email.
Scenario 2

  • Stopped the task. I didn't enable Node 1, its still out of commission

  • Ran the task. I received an email to check my NLB

  • Added Node 1 back to the NLB I am still receiving check NLB failures every minute (In production: I will pause the script for every hour instead of every five minutes)

Any reason why? It may have to do something with my do while loop perhaps?

cls
Import-Module NetworkLoadBalancingClusters
$nodeStatus = Get-NlbClusterNode -hostname "computer1"
$status = $nodeStatus[0].State.ToString()
$status1 = $nodeStatus[1].State.ToString()
do {
$flag = 1
if ($status -match "converged" -and $status1 -match "converged")
{
$message = "good"
}
else {
$message2 = "check nlb"
$flag = $flag + 1
}
if ($flag -igt 1) {
Write-Host "Sending Email notification to user"
$smtpServer = "smtp.sample.com"
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$msg = New-Object Net.Mail.MailMessage
$msg.To.Add("sample.google.com")
$msg.From = "SPagent@sample.com"
$msg.Subject = "NLB node(s) is not started"
$msg.Body =  $message2 
$smtp.Send($msg)
$body = ""
Start-Sleep -minutes 5
}

$response = "Y"
 }
 while ($response -eq "Y")
Était-ce utile?

La solution

In your script you get the status of the nodes once, then you go into your infinite loop. So the status of your nodes never change, and that's why you don't get a notification email in senario 1. Then with senario 2 is says the node 1 is offline and then it never updates the status of it, so that's why you keep getting emails. What you want to do is keep getting the status of your nodes. So you might want to do something like this:

do {
    $nodeStatus = Get-NlbClusterNode -hostname "computer1"
    $status = $nodeStatus[0].State.ToString()
    $status1 = $nodeStatus[1].State.ToString()
    $flag = 1
    # do your normal stuff ...
}
while ($response -eq "Y")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top