Powershell + Nagios 监控 VEEAM 备份状态
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Powershell + Nagios 监控 VEEAM 备份状态相关的知识,希望对你有一定的参考价值。
豆子平常一般习惯用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 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无法识别我们自己写的外部命令。
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服务器,测试该命令是否能够识别
[[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服务,然后在页面即可看见结果。
结果和VEEAM 管理界面一致
本文出自 “麻婆豆腐” 博客,请务必保留此出处http://beanxyz.blog.51cto.com/5570417/1981136
以上是关于Powershell + Nagios 监控 VEEAM 备份状态的主要内容,如果未能解决你的问题,请参考以下文章