1

NLB 信息
负载均衡器:LoadBal
NODE 1
NODE 2

每当节点不充当负载平衡服务器时,我都想接收电子邮件。我有一个连续运行以下脚本的计划任务。当节点不充当负载平衡服务器时,此脚本会向我发送电子邮件。

我的测试场景:

场景 1:
从 NLB 停止节点 1 但我没有收到电子邮件。
方案 2

  • 停止了任务。我没有启用节点 1,它仍然无法使用

  • 跑任务。我收到一封电子邮件来检查我的 NLB

  • 将节点 1 添加回 NLB 我仍然每分钟都会收到检查 NLB 故障(在生产中:我将每隔一小时而不是每五分钟暂停一次脚本)

有什么理由吗?也许它可能与我的 do while 循环有关?

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")
4

1 回答 1

0

在您的脚本中,您可以获得一次节点的状态,然后进入无限循环。所以你的节点的状态永远不会改变,这就是为什么你没有在 senario 1 中收到通知电子邮件。然后用 senario 2 说节点 1 处于脱机状态,然后它永远不会更新它的状态,所以这就是为什么你保持收到电子邮件。您想要做的是不断获取节点的状态。所以你可能想做这样的事情:

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")
于 2014-02-03T21:10:13.020 回答