zabbix監控windows DHCP server

聆听城市喧哗發表於2024-03-08

一、準備在HDCP伺服器上建立兩個指令碼,check_dhcpscop.ps1 和 check_dhcpscop_value.ps1

》1、建立powershell"check_dhcpscop.ps1"

#獲取DHCP作用域,輸出結果要為json格式,key值格式必須為{#NAME},必須大寫
$scops = Get-DhcpServerv4Scope |select @{name="{#SCOPNAME}";expression={$_.Name.replace(' ','')}}|ConvertTo-Json

@"
{"data":$scops}
"@

》2、建立powershell“ check_dhcpscop_value.ps”

Param($scopname, $propname)

#獲取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.replace(' ','') -eq ($scopname + $ID)}).$propname

3》兩個指令碼都放在dhcp伺服器的 c:\zabbix\script\

二、建立zabbix 模板,新記事本,複製內容,字尾為.yaml hdcp.yamn

zabbix_export:
  version: '6.0'
  date: '2023-02-02T03:19:35Z'
  groups:
    -
      uuid: 846977d1dfed4968bc5f8bdb363285bc
      name: 'Templates/Operating systems'
  templates:
    -
      uuid: 76e0de58829f458285537935d85819d3
      template: 'TBI Windows DHCP Server by Zabbix agent'
      name: 'TBI Windows DHCP Server by Zabbix agent'
      description: |
        Official Windows template. Requires agent of Zabbix 4.4 and newer.
        
        
        You can discuss this template or leave feedback on our forum https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/387224-discussion-thread-for-official-zabbix-template-for-windows
        
        Template tooling version used: 0.41
      groups:
        -
          name: 'Templates/Operating systems'
      items:
        -
          uuid: 4732f2defd2e49d7ab9dd75b212d0de3
          name: 'Zabbix agent ping'
          type: ZABBIX_ACTIVE
          key: agent.ping
          history: 7d
          description: 'The agent always returns 1 for this item. It could be used in combination with nodata() for availability check.'
          valuemap:
            name: 'Zabbix agent ping status'
          tags:
            -
              tag: component
              value: system
          triggers:
            -
              uuid: f1fc1bad92034af8a14aeaf56a125c84
              expression: 'nodata(/TBI Windows DHCP Server by Zabbix agent/agent.ping,{$AGENT.NODATA_TIMEOUT})=1'
              name: 'Zabbix agent is not available'
              event_name: 'Zabbix agent is not available (or nodata for {$AGENT.NODATA_TIMEOUT})'
              priority: AVERAGE
              description: 'For active agents, nodata() with agent.ping is used with {$AGENT.NODATA_TIMEOUT} as time threshold.'
              manual_close: 'YES'
              tags:
                -
                  tag: scope
                  value: availability
        -
          uuid: 9de081e14a0745a58d69ebaa4860d1c3
          name: Uptime
          type: ZABBIX_ACTIVE
          key: system.uptime
          delay: 30s
          history: 2w
          trends: 0d
          units: uptime
          description: 'System uptime in ''N days, hh:mm:ss'' format.'
          tags:
            -
              tag: component
              value: system
          triggers:
            -
              uuid: 05f93c476eef49658a165a06510150e2
              expression: 'last(/TBI Windows DHCP Server by Zabbix agent/system.uptime)<10m'
              name: 'Host has been restarted'
              event_name: 'Host has been restarted (uptime < 10m)'
              priority: WARNING
              description: 'The device uptime is less than 10 minutes.'
              manual_close: 'YES'
              tags:
                -
                  tag: scope
                  value: notice
      discovery_rules:
        -
          uuid: 12bfdc6715774ead881f595600cfcfed
          name: 'DHCP Scope Discovery'
          key: check_dhcpscop
          delay: 5m
          filter:
            conditions:
              -
                macro: '{#SCOPNAME}'
                formulaid: A
          item_prototypes:
            -
              uuid: e0d67fe51ce842c9a4a67cd625ce28f5
              name: 'DHCP Scop Free_{#SCOPNAME}'
              key: 'get_dhcpinfor[{#SCOPNAME},Free]'
              trends: '0'
              status: DISABLED
              discover: NO_DISCOVER
              value_type: TEXT
            -
              uuid: 04633f19dbe44a45b729785ce5d88955
              name: 'DHCP Scop PerCentageInUse_{#SCOPNAME}'
              key: 'get_dhcpinfor[{#SCOPNAME},PercentageInUse]'
              delay: 5m
              value_type: FLOAT
              preprocessing:
                -
                  type: MULTIPLIER
                  parameters:
                    - '1'
              trigger_prototypes:
                -
                  uuid: d3337b91cf8a45f7a47790e8da3a03d2
                  expression: 'avg(/TBI Windows DHCP Server by Zabbix agent/get_dhcpinfor[{#SCOPNAME},PercentageInUse],3m)>=95'
                  recovery_mode: RECOVERY_EXPRESSION
                  recovery_expression: 'avg(/TBI Windows DHCP Server by Zabbix agent/get_dhcpinfor[{#SCOPNAME},PercentageInUse],3m)<90'
                  name: '{#SCOPNAME} Scope  usage above 95%'
                  priority: AVERAGE
            -
              uuid: f0dc48a0680a4ff9be34941ff94e8dcb
              name: 'DHCP Scop State_{#SCOPNAME}'
              key: 'get_dhcpinfor[{#SCOPNAME},State]'
              delay: 5m
              trends: '0'
              value_type: TEXT
              trigger_prototypes:
                -
                  uuid: a9266d377a53464082adf219da51b121
                  expression: 'last(/TBI Windows DHCP Server by Zabbix agent/get_dhcpinfor[{#SCOPNAME},State])="Inactive"'
                  recovery_mode: RECOVERY_EXPRESSION
                  recovery_expression: 'last(/TBI Windows DHCP Server by Zabbix agent/get_dhcpinfor[{#SCOPNAME},State])="Active"'
                  name: '{#SCOPNAME} Scope Static Inactice'
                  priority: AVERAGE
            -
              uuid: b7b5de331d0748f58f0b24fe968dd165
              name: 'DHCP Scop Use_{#SCOPNAME}'
              key: 'get_dhcpinfor[{#SCOPNAME},Use]'
              trends: '0'
              status: DISABLED
              discover: NO_DISCOVER
              value_type: TEXT
          graph_prototypes:
            -
              uuid: 1e336fc86f53426fa4e840335869d57a
              name: 'Dhcp Scop PerCentageInUse {#SCOPNAME}'
              percent_left: '100'
              graph_items:
                -
                  color: 1A7C11
                  calc_fnc: ALL
                  item:
                    host: 'TBI Windows DHCP Server by Zabbix agent'
                    key: 'get_dhcpinfor[{#SCOPNAME},PercentageInUse]'
      tags:
        -
          tag: class
          value: os
        -
          tag: target
          value: windows
      macros:
        -
          macro: '{$AGENT.NODATA_TIMEOUT}'
          value: 30m
          description: 'No data timeout for active agents. Consider to keep it relatively high.'
        -
          macro: '{$CPU.INTERRUPT.CRIT.MAX}'
          value: '50'
          description: 'The critical threshold of the % Interrupt Time counter.'
        -
          macro: '{$CPU.PRIV.CRIT.MAX}'
          value: '30'
          description: 'The threshold of the % Privileged Time counter.'
        -
          macro: '{$CPU.QUEUE.CRIT.MAX}'
          value: '3'
          description: 'The threshold of the Processor Queue Length counter.'
        -
          macro: '{$CPU.UTIL.CRIT}'
          value: '90'
          description: 'The critical threshold of the CPU utilization in %.'
        -
          macro: '{$IF.ERRORS.WARN}'
          value: '2'
        -
          macro: '{$IF.UTIL.MAX}'
          value: '90'
        -
          macro: '{$IFCONTROL}'
          value: '1'
        -
          macro: '{$MEM.PAGE_SEC.CRIT.MAX}'
          value: '1000'
          description: 'The warning threshold of the Memory Pages/sec counter.'
        -
          macro: '{$MEM.PAGE_TABLE_CRIT.MIN}'
          value: '5000'
          description: 'The warning threshold of the Free System Page Table Entries counter.'
        -
          macro: '{$MEMORY.UTIL.MAX}'
          value: '90'
          description: 'The warning threshold of the Memory util item.'
        -
          macro: '{$NET.IF.IFALIAS.MATCHES}'
          value: '.*'
          description: 'This macro is used in Network interface discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$NET.IF.IFALIAS.NOT_MATCHES}'
          value: CHANGE_THIS
          description: 'This macro is used in Network interface discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$NET.IF.IFDESCR.MATCHES}'
          value: '.*'
          description: 'This macro is used in Network interface discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$NET.IF.IFDESCR.NOT_MATCHES}'
          value: CHANGE_THIS
          description: 'This macro is used in Network interface discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$NET.IF.IFNAME.MATCHES}'
          value: '.*'
          description: 'This macro is used in Network interface discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$NET.IF.IFNAME.NOT_MATCHES}'
          value: Miniport|Virtual|Teredo|Kernel|Loopback|Bluetooth|HTTPS|6to4|QoS|Layer
          description: 'This macro is used in Network interface discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$SERVICE.NAME.MATCHES}'
          value: '^.*$'
          description: 'This macro is used in Service discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$SERVICE.NAME.NOT_MATCHES}'
          value: '^(?:RemoteRegistry|MMCSS|gupdate|SysmonLog|clr_optimization_v.+|sppsvc|gpsvc|Pml Driver HPZ12|Net Driver HPZ12|MapsBroker|IntelAudioService|Intel\(R\) TPM Provisioning Service|dbupdate|DoSvc|CDPUserSvc_.+|WpnUserService_.+|OneSyncSvc_.+|WbioSrvc|BITS|tiledatamodelsvc|GISvc|ShellHWDetection|TrustedInstaller|TabletInputService|CDPSvc|wuauserv)$'
          description: 'This macro is used in Service discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$SERVICE.STARTUPNAME.MATCHES}'
          value: '^(?:automatic|automatic delayed)$'
          description: 'This macro is used in Service discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$SERVICE.STARTUPNAME.NOT_MATCHES}'
          value: '^(?:manual|disabled)$'
          description: 'This macro is used in Service discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$SWAP.PFREE.MIN.WARN}'
          value: '20'
          description: 'The warning threshold of the minimum free swap.'
        -
          macro: '{$SYSTEM.FUZZYTIME.MAX}'
          value: '60'
          description: 'The threshold for difference of system time in seconds.'
        -
          macro: '{$VFS.DEV.DEVNAME.MATCHES}'
          value: '.*'
          description: 'This macro is used in physical disks discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.DEV.DEVNAME.NOT_MATCHES}'
          value: _Total
          description: 'This macro is used in physical disks discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.DEV.READ.AWAIT.WARN}'
          value: '0.02'
          description: 'Disk read average response time (in s) before the trigger would fire.'
        -
          macro: '{$VFS.DEV.UTIL.MAX.WARN}'
          value: '95'
          description: 'The warning threshold of disk time utilization in percent.'
        -
          macro: '{$VFS.DEV.WRITE.AWAIT.WARN}'
          value: '0.02'
          description: 'Disk write average response time (in s) before the trigger would fire.'
        -
          macro: '{$VFS.FS.FREE.MIN.CRIT}'
          value: 5G
          description: 'The critical threshold of the filesystem utilization.'
        -
          macro: '{$VFS.FS.FREE.MIN.WARN}'
          value: 10G
          description: 'The warning threshold of the filesystem utilization.'
        -
          macro: '{$VFS.FS.FSDRIVETYPE.MATCHES}'
          value: fixed
          description: 'This macro is used in filesystems discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.FS.FSDRIVETYPE.NOT_MATCHES}'
          value: ^\s$
          description: 'This macro is used in filesystems discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.FS.FSNAME.MATCHES}'
          value: '.*'
          description: 'This macro is used in filesystems discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.FS.FSNAME.NOT_MATCHES}'
          value: '^(?:/dev|/sys|/run|/proc|.+/shm$)'
          description: 'This macro is used in filesystems discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.FS.FSTYPE.MATCHES}'
          value: '.*'
          description: 'This macro is used in filesystems discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.FS.FSTYPE.NOT_MATCHES}'
          value: ^\s$
          description: 'This macro is used in filesystems discovery. Can be overridden on the host or linked template level.'
        -
          macro: '{$VFS.FS.PUSED.MAX.CRIT}'
          value: '90'
          description: 'The critical threshold of the filesystem utilization in percent.'
        -
          macro: '{$VFS.FS.PUSED.MAX.WARN}'
          value: '80'
          description: 'The warning threshold of the filesystem utilization in percent.'
      dashboards:
        -
          uuid: a6148375a09e403193d2457a09a6d880
          name: 'Network interfaces'
          pages:
            -
              widgets:
                -
                  type: GRAPH_PROTOTYPE
                  width: '24'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '2'
                    -
                      type: INTEGER
                      name: columns
                      value: '1'
                    -
                      type: INTEGER
                      name: rows
                      value: '1'
        -
          uuid: 15f071590aff491db3e5af07ddcbf4ec
          name: 'System performance'
          pages:
            -
              widgets:
                -
                  type: GRAPH_CLASSIC
                  width: '12'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '0'
                -
                  type: GRAPH_CLASSIC
                  x: '12'
                  width: '12'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '1'
                -
                  type: GRAPH_CLASSIC
                  'y': '5'
                  width: '12'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '0'
                -
                  type: GRAPH_CLASSIC
                  x: '12'
                  'y': '5'
                  width: '12'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '0'
                -
                  type: GRAPH_PROTOTYPE
                  'y': '10'
                  width: '24'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '2'
                    -
                      type: INTEGER
                      name: columns
                      value: '1'
                    -
                      type: INTEGER
                      name: rows
                      value: '1'
                -
                  type: GRAPH_PROTOTYPE
                  'y': '15'
                  width: '24'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '2'
                    -
                      type: INTEGER
                      name: columns
                      value: '1'
                    -
                      type: INTEGER
                      name: rows
                      value: '1'
                -
                  type: GRAPH_PROTOTYPE
                  'y': '20'
                  width: '24'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '2'
                    -
                      type: INTEGER
                      name: columns
                      value: '1'
                    -
                      type: INTEGER
                      name: rows
                      value: '1'
                -
                  type: GRAPH_PROTOTYPE
                  'y': '25'
                  width: '24'
                  height: '5'
                  fields:
                    -
                      type: INTEGER
                      name: source_type
                      value: '2'
                    -
                      type: INTEGER
                      name: columns
                      value: '1'
                    -
                      type: INTEGER
                      name: rows
                      value: '1'
      valuemaps:
        -
          uuid: 8e51851734de459b897654b55e097ed9
          name: 'Win32_NetworkAdapter::AdapterTypeId'
          mappings:
            -
              value: '0'
              newvalue: 'Ethernet 802.3'
            -
              value: '1'
              newvalue: 'Token Ring 802.5'
            -
              value: '2'
              newvalue: 'Fiber Distributed Data Interface (FDDI)'
            -
              value: '3'
              newvalue: 'Wide Area Network (WAN)'
            -
              value: '4'
              newvalue: LocalTalk
            -
              value: '5'
              newvalue: 'Ethernet using DIX header format'
            -
              value: '6'
              newvalue: ARCNET
            -
              value: '7'
              newvalue: 'ARCNET (878.2)'
            -
              value: '8'
              newvalue: ATM
            -
              value: '9'
              newvalue: Wireless
            -
              value: '10'
              newvalue: 'Infrared Wireless'
            -
              value: '11'
              newvalue: Bpc
            -
              value: '12'
              newvalue: CoWan
            -
              value: '13'
              newvalue: '1394'
        -
          uuid: d1945b12b60241b59e1576f119fd4085
          name: 'Win32_NetworkAdapter::NetConnectionStatus'
          mappings:
            -
              value: '0'
              newvalue: Disconnected
            -
              value: '1'
              newvalue: Connecting
            -
              value: '2'
              newvalue: Connected
            -
              value: '3'
              newvalue: Disconnecting
            -
              value: '4'
              newvalue: 'Hardware Not Present'
            -
              value: '5'
              newvalue: 'Hardware Disabled'
            -
              value: '6'
              newvalue: 'Hardware Malfunction'
            -
              value: '7'
              newvalue: 'Media Disconnected'
            -
              value: '8'
              newvalue: Authenticating
            -
              value: '9'
              newvalue: 'Authentication Succeeded'
            -
              value: '10'
              newvalue: 'Authentication Failed'
            -
              value: '11'
              newvalue: 'Invalid Address'
            -
              value: '12'
              newvalue: 'Credentials Required'
        -
          uuid: 000cb16205a5446589dcbfaf400dc6ad
          name: 'Windows service state'
          mappings:
            -
              value: '0'
              newvalue: Running
            -
              value: '1'
              newvalue: Paused
            -
              value: '2'
              newvalue: 'Start pending'
            -
              value: '3'
              newvalue: 'Pause pending'
            -
              value: '4'
              newvalue: 'Continue pending'
            -
              value: '5'
              newvalue: 'Stop pending'
            -
              value: '6'
              newvalue: Stopped
            -
              value: '7'
              newvalue: Unknown
            -
              value: '255'
              newvalue: 'No such service'
        -
          uuid: 247752b40d1642369bb9f70ace9be325
          name: zabbix.host.available
          mappings:
            -
              value: '0'
              newvalue: 'not available'
            -
              value: '1'
              newvalue: available
            -
              value: '2'
              newvalue: unknown
        -
          uuid: beee6a48ce11416788566615ef129743
          name: 'Zabbix agent ping status'
          mappings:
            -
              value: '1'
              newvalue: Up

三、將dhcp.yaml模板匯入到zabbix中

三 、在DHCP伺服器上的C盤的zabbix檔案zabbix_agentd.conf 中自定義使用者引數

UserParameter=check_dhcpscop,powershell c:\zabbix\script\check_dhcpscop.ps1
UserParameter=check_dhcpscop_value[*],powershell c:\zabbix\script\check_dhcpscop_value.ps1 $1 $2c

注意:

zabbix的使用者引數限制使用特殊字元和空格,假設你的作用域名字是Vlan 10(帶有空格),則會出現傳參錯誤。
這裡在check_dhcpscop.ps1裡做了修改,會將空格去除。

四、以管理員身份執行一下兩個指令碼check_dhcpscop.ps1 和 check_dhcpscop_value.ps1,看是否有報錯。

五、重啟一下zabbix-agent服務

六、到zabbix平臺可以看到我們的DHCP資訊就上來了

參考:

1:https://blog.csdn.net/qq_42906357/article/details/128846407

2:https://blog.csdn.net/qq_42906357/article/details/128631225?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-16-128631225-blog-132167834.235%5Ev43%5Epc_blog_bottom_relevance_base1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-16-128631225-blog-132167834.235%5Ev43%5Epc_blog_bottom_relevance_base1&utm_relevant_index=22

相關文章