Advertisement
rmonakhov

Get-ZabbixAgentProxy.ps1

May 7th, 2020
3,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Defining variables
  2. $ZabbixProxies=
  3. $InstallDir=
  4.  
  5. # getting IP address
  6. [string]$IPAddress = [array]((Get-WmiObject -Class win32_networkadapterconfiguration | Where-Object {$_.defaultIPGateway -ne $null}).IPAddress)[0]
  7.  
  8. # defining networks and proxies
  9. $ip_ranges= @(
  10.     ("net1",        "start_ip1",           "end_ip1",         "proxy1"),
  11.     ("net2",        "start_ip2",           "end_ip2",         "proxy2"),
  12.     ("net3",        "start_ip3",           "end_ip3",         "proxy3")
  13. )
  14.  
  15. # defining Active Proxy
  16. ForEach ($range in $ip_ranges) {
  17.     if (([version]$IPAddress -ge [version]$range[1]) -AND ([version]$IPAddress -le [version]$range[2])) {
  18.         $ZabbixActiveProxy = $range[3]
  19.         $Changed = True
  20.     }
  21. }
  22.  
  23. # changing conf
  24. if ($Changed){
  25.     Write-Output "Server=$ZabbixProxies`nServerActive=$ZabbixActiveProxy | Out-File $InstallDir\zabbix_agentd.conf.d\server.conf" -Force -Encoding ASCII
  26.     Restart-Service "Zabbix Agent"
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement