1.新建名为的check_dhcpscop.ps1脚本,用于获取当前所有的作用域名称,内容如下:
#获取DHCP作用域,输出结果要为json格式,key值格式必须为{#NAME},必须大写 $scops = Get-DhcpServerv4Scope |select @{name="{#SCOPNAME}";expression={$_.Name}}|ConvertTo-Json @" {"data":$scops} "@
zabbix server运行 zabbix_get -s 10.10.101.101 -k check_dhcpscop 命令,结果如下:
{"data":[ { "{#Scopname}": "Vlan7-v" }, { "{#Scopname}": "Vlan8-A" }, { "{#Scopname}": "Vlan9-p" }, { "{#Scopname}": "Vlan3-g" }, { "{#Scopname}": "Vlan31-T" }, { "{#Scopname}": "Vlan32-o" }, { "{#Scopname}": "Vlan4-o" }, { "{#Scopname}": "Vlan6-n" } ]}
新建名为的check_dhcpscop_value.ps1脚本,用于获取各个作用域的状态、IP使用情况,内容如下:
Param($scopname,$propname) #$scopname = "Vlan8-AP" #$propname = "PercentageInUse" #获取DHCP作用域当前状态及IP分配情况 $scops = Get-DhcpServerv4Scope |select Name,@{name="ScopeID";expression={$_.ScopeID.IPAddressToString}},State $scops_ipusages = Get-DhcpServerv4ScopeStatistics |Select @{name="ScopeID";expression={$_.ScopeID.IPAddressToString}},PercentageInUse #将两个对象合并为一个 foreach ($scop in $scops) { $scop_ipusage = $scops_ipusages | Where-Object {$_.ScopeID -eq $scop.ScopeID} $scop | Add-Member -MemberType NoteProperty -Name PercentageInUse -Value $scop_ipusage.PercentageInUse -Force } ($scops | ? {$_.Name -eq $scopname}).$propname
zabbix server运行 zabbix_get -s 10.10.101.101 -k check_dhcpscop_value[Vlan7-v,State] 命令,返回值为 Active
2.修改zabbix agent配置文件,然后重启agent,如下:
UserParameter=check_dhcpscop,powershell c:zabbixscriptcheck_dhcpscop.ps1 UserParameter=check_dhcpscop_value[*],powershell c:zabbixscriptcheck_dhcpscop_value.ps1 $1 $2 #表示后面可以加两个参数
3.在DHCP模板中新建发现规则,如下:
key需要和配置文件中的UserParameter=check_dhcpscop一致
添加filter,然后就可以发现各个scop了,如下:
4.添加item prototype,获取作用域状态,如下:
获取作用域IP使用率: