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


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
[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


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服务,然后在页面即可看见结果。

881f6f4d6ea5332ab370c3aee93e0ab2.png


结果和VEEAM 管理界面一致


69a3a1050c95df7e7bb33fc861a6b9b0.png







本文转自 beanxyz 51CTO博客,原文链接:http://blog.51cto.com/beanxyz/1981136,如需转载请自行联系原作者

目录
相关文章
|
8月前
|
监控 小程序
利用PowerShell写的一个CPU监控小程序
业务部门需要,所以写的一个CPU监控小程序,有窗口显示,同时会在当前目录生成日志,有需要的自取,复制代码,TXT另存为xx.ps1即可。 仅供学习交流。
125 0
|
监控 Windows
Windows Server端口监控之powershell脚本
powershell检测端口并重启程序
603 0
|
监控 C# 数据安全/隐私保护
多进程监控自动关机工具升级远程关闭多台server——C# works with PowerShell
之前给单位做过一个多进程监控的自动关机工具,详见那篇blog。 这次领导又加了需求,说要等进程监控结束后,不止需要关闭主控端server,还需要关闭其他servers。于是就用到了我上篇文章所介绍的知识——通过PowerShell来远程管理计算机。
1240 0
|
3月前
|
存储 Ubuntu Linux
windows可以安装Ubuntu,ubuntu上也可以安装Powershell
powerhsell除了可以在windows上使用外,还可以在Ubuntu上部署开发环境。下面介绍Ubuntu上安装powershell的方法。
50 0
|
5月前
|
Shell Linux 开发工具
windows中cmd和PowerShell批处理命令
之前在 Git 批量删除本地分支,有用到 Linux 或 MacOS 下的批处理命令,这个命令中的 grep、xargs 本身是 Shell script,在 windows 中的 cmd 和 PowerShell 中是不能用的
51 0
|
8月前
|
JavaScript Windows
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题