|
豆子平常一般习惯用Nagios监控系统的状态。平常公司使用VEEAM来管理文件的备份和还原,备份的结果一般通过Email发送给豆子。今天心血来潮,想把这个备份的状态在Nagios的监控界面上也展现出来。
因为VEEAM本身提供了PowerShell的模块,因此豆子可以通过NSclient++客户端来调用自定义的PowerShell脚本,从而实现监控的目的。
1) 自定义的 Powershell脚本 veeam_backup.ps1, 脚本很简单,根据不同的结果返回不同的exit的值。
Nagios里面的定义是
- 0- OK
- 1- Warning
- 2- Critial
- 3- Unknow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| 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
}
|
执行看看,成功!
1
2
| 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 配置文件关键配置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| [/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服务器,测试该命令是否能够识别
1
2
| [iyunv@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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| 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 管理界面一致
|
|
|