豆子日常通常習慣用Nagios監控系統的狀態。日常公司使用VEEAM來管理文件的備份和還原,備份的結果通常經過Email發送給豆子。今天心血來潮,想把這個備份的狀態在Nagios的監控界面上也展示出來。ios
由於VEEAM自己提供了PowerShell的模塊,所以豆子能夠經過NSclient++客戶端來調用自定義的PowerShell腳本,從而實現監控的目的。shell
1) 自定義的 Powershell腳本 veeam_backup.ps1, 腳本很簡單,根據不一樣的結果返回不一樣的exit的值。windows
Nagios裏面的定義是api
0- OKbash
1- Warning服務器
2- Critialsession
3- Unknowide
Param ( # Param1 help description [string] $name ) Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue Disconnect-vbrserver Connect-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") { $status Write-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沒法識別咱們本身寫的外部命令。spa
nisclient.ini 配置文件關鍵配置以下
[/settings/NRPE/server] verify mode = none insecure = true extended response = 0 allow arguments = true allow nasty characters = true [/modules] CheckHelpers = 1 CheckNSCP = 1 CheckDisk = 1 CheckSystem = 1 NSClientServer = 1 CheckEventLog = 1 NSCAClient = 1 NRPEServer = enabled CheckExternalScripts = enabled [/settings/NRPE/server] verify mode = none insecure = true port = 9999 extended response = 0 allow arguments = true allow 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服務器,測試該命令是否可以識別
[root@sydnagios 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服務,而後在頁面便可看見結果。
結果和VEEAM 管理界面一致