Advertisement
Guest User

Untitled

a guest
Feb 8th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. # Author: Romain Si
  2. # Description: Query DHCP Server information
  3. #
  4. # This script is intended for use with Zabbix > 3.x
  5. #
  6. #
  7. # USAGE:
  8. # as a script: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -command "& C:\Zabbix\zabbix_dhcp_scope.ps1 <ITEM_TO_QUERY> <SCOPE>"
  9. # as an item: dhcp[<ITEM_TO_QUERY>,<SCOPE>]
  10. #
  11. # Add to Zabbix Agent
  12. # UserParameter=dhcp[*],powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Program Files\Zabbix Agent\zabbix_dhcp_scope.ps1" "$1" "$2"
  13. #
  14.  
  15. $ITEM = [string]$args[0]
  16. $ID = [string]$args[1]
  17.  
  18. switch ($ITEM) {
  19. "Discovery" {
  20. # Open JSON object
  21. $output = "{`"data`":["
  22. $query = Get-DhcpServerv4ScopeStatistics | Select-Object ScopeId
  23. $count = $query | Measure-Object
  24. $count = $count.count
  25. foreach ($object in $query) {
  26. $Id = [string]$object.ScopeId
  27. if ($count -eq 1) {
  28. $output = $output + "{`"{#SCOPEID}`":`"$Id`"}"
  29. } else {
  30. $output = $output + "{`"{#SCOPEID}`":`"$Id`"},"
  31. }
  32. $count--
  33. }
  34. # Close JSON object
  35. $output = $output + "]}"
  36. Write-Host $output
  37. }
  38.  
  39. "ScopeFree" {
  40. $query = Get-DhcpServerv4ScopeStatistics | Where-Object {$_.ScopeId -like "*$ID*"} | Select-Object Free
  41. foreach ($object in $query) {
  42. $Free = [string]$object.Free}
  43. $Free
  44. }
  45.  
  46. "ScopeInUse" {
  47. $query = Get-DhcpServerv4ScopeStatistics | Where-Object {$_.ScopeId -like "*$ID*"} | Select-Object InUse
  48. foreach ($object in $query) {
  49. $InUse = [string]$object.InUse}
  50. $InUse
  51. }
  52.  
  53. "ScopePercentageInUse" {
  54. $query = Get-DhcpServerv4ScopeStatistics | Where-Object {$_.ScopeId -like "*$ID*"} | Select-Object PercentageInUse
  55. foreach ($object in $query) {
  56. $PercentageInUse = [string]$object.PercentageInUse}
  57. $PercentageInUse
  58. }
  59.  
  60. "ScopeReserved" {
  61. $query = Get-DhcpServerv4ScopeStatistics | Where-Object {$_.ScopeId -like "*$ID*"} | Select-Object Reserved
  62. foreach ($object in $query) {
  63. $Reserved = [string]$object.Reserved}
  64. $Reserved
  65. }
  66.  
  67. default {
  68. Write-Host "-- ERREUR -- : Besoin d'une option !"
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement