標籤:nagios veeam powershell nsclient
豆子平常一般習慣用Nagios監控系統的狀態。平常公司使用VEEAM來管理檔案的備份與還原,備份的結果一般通過Email發送給豆子。今天心血來潮,想把這個備份的狀態在Nagios的監控介面上也展現出來。
因為VEEAM本身提供了PowerShell的模組,因此豆子可以通過NSclient++用戶端來調用自訂的PowerShell指令碼,從而實現監控的目的。
1) 自訂的 Powershell指令碼 veeam_backup.ps1, 指令碼很簡單,根據不同的結果返回不同的exit的值。
Nagios裡面的定義是
0- OK
1- Warning
2- Critial
3- Unknow
Param( # Param1 help description [string] $name)Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinueDisconnect-vbrserverConnect-VBRServer -Server drvbr01 -User omnicom\yuan.li -Password Goat201510$job = Get-VBRJob -Name $name$name = "‘" + $name + "‘"if ($job -eq $null){Write-Host "UNKNOWN! No such a job: $name."exit 3}$status = $job.GetLastResult()if($($job.findlastsession()).State -eq "Working"){Write-Host "OK - Job: $name is currently in progress."exit 0}if ($status -eq "Failed"){Write-Host "CRITICAL! Errors were encountered during the backup process of the following job: $name."exit 2}if($status -eq "Success"){ $lastrun=$job.scheduleOptions.LatestRunLocal write-host "OK - Job: $name was completed succesfully, Lastrun finished at $lastrun " exit 0}if ($status -ne "Success"){ $statusWrite-Host "WARNING! Job $name didn‘t fully succeed."exit 1}
執行看看,成功!
PS C:\Windows\system32> C:\veeam_backup.ps1 -name "Finance Servers - Backup"OK - Job: ‘Finance Servers - Backup‘ was completed succesfully, Lastrun finished at 11/12/2017 23:30:00
2) 第二步需要修改我們的Nsclient++的設定檔 nsclient.ini 這個地方一定要確保格式正確 不然nagios無法識別我們自己寫的外部命令。
nisclient.ini 設定檔關鍵配置如下
[/settings/NRPE/server] verify mode = noneinsecure = trueextended response = 0allow arguments = trueallow nasty characters = true[/modules] CheckHelpers = 1CheckNSCP = 1CheckDisk = 1CheckSystem = 1NSClientServer = 1CheckEventLog = 1NSCAClient = 1NRPEServer = enabledCheckExternalScripts = enabled[/settings/NRPE/server] verify mode = noneinsecure = trueport = 9999extended response = 0allow arguments = trueallow nasty characters = true[/settings/external scripts] allow arguments = true[/settings/external scripts/scripts]financejob = cmd /c echo c:\\veeam_backup.ps1 $ARG1$; exit($lastexitcode) | powershell.exe -command -
修改完畢,重啟nscp服務之後,在SSH登入Nagios伺服器,測試該命令是否能夠識別
[[email protected] libexec]# ./check_nrpe -H drvbr01 -c financejob -a "Finance Servers - Backup"OK - Job: ‘Finance Servers - Backup‘ was completed succesfully, Lastrun finished at 11/12/2017 23:30:00
3) 配置Nagios的command.cfg, host.cfg和service.cfg
define command { command_name check_veeamjob command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c $ARG1$ -a $ARG2$}define host{ use windows-server ; host_name DRVBR01 ; alias DRVBR01 ; address 10.9.1.74 ; parents SYD3750COLO } define service{ use generic-service host_name DRVBR01 servicegroups windows-services service_description VEEAM REPLICATION JOB - Finance check_command check_veeamjob!financejob!‘Finance Servers - Replication‘ }
4)測試
重啟Nagios服務,然後在頁面即可看見結果。
650) this.width=650;" src="https://s3.51cto.com/oss/201711/13/881f6f4d6ea5332ab370c3aee93e0ab2.png" style="float:none;" title="2.PNG" alt="881f6f4d6ea5332ab370c3aee93e0ab2.png" />
結果和VEEAM 管理介面一致
650) this.width=650;" src="https://s2.51cto.com/oss/201711/13/69a3a1050c95df7e7bb33fc861a6b9b0.png" style="float:none;" title="3.PNG" alt="69a3a1050c95df7e7bb33fc861a6b9b0.png" />
本文出自 “麻婆豆腐” 部落格,請務必保留此出處http://beanxyz.blog.51cto.com/5570417/1981136
Powershell + Nagios 監控 VEEAM 備份狀態