Ad Widget

Collapse

Zabbix Proxy Server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StephenJ
    Member
    • Dec 2018
    • 44

    #1

    Zabbix Proxy Server

    I have setup a zabbix proxy server on a customer's site and running well. I am now about to setup another proxy server on a second customer's site. This setup is slightly different. They are currently setup and reporting into zabbix server via a nat address, over VPN. Currently they have around 90 servers. I will need to update each config file on each server and point it to the proxy server instead.

    Is there a way I can use zabbix to stop the service on the server, edit the host file and change the server ip? I don't really want to log on to 90 servers manually and point them to the new proxy server.

    Running zabbix version 4.0
  • steeladept
    Member
    • Sep 2018
    • 69

    #2
    Depends on how the agents are currently setup and how good your scripting skills are. You can create a script for the agent to run that will kick off a second script that will do the heavy lifting, but that means the agent already needs configured to be able to do that in the first place. It also assumes you have the correct permissions setup on each server for that script to run and if it is a mixed OS environment it becomes even more complicated. So in short, yes it is theoretically possible, but in reality, we would need a lot more information before we could help you answer that question for your situation. There is nothing built in to the Zabbix server, however, that does that easily to my knowledge.

    Comment

    • StephenJ
      Member
      • Dec 2018
      • 44

      #3
      Yes I am looking at a much easier way of doing it. On the 90 odd servers, I know the server=x.x.x.x address is on line 88. Just been having a look at the config file. I will need to change line 88 on each server to point to server=y.y.y.y I am now thinking of just creating a vb script that looks at line 88 and replace it. I could then create some sort of batch file that will look in a text file for the list of servers, stop zabbix service, edit config file, start zabbix service.

      Comment

      • steeladept
        Member
        • Sep 2018
        • 69

        #4
        If they are all newer windows machines, may I recommend Powershell instead. It has a very easy way of doing the change. Just add the server IP's between the Parenthesis as indicated (don't save the anglebrackets) and make sure your path is set as appropriate (in my example I use c:\zabbix as the source folder):

        stop-service "Zabbix Agent"
        Rename-Item -Path "c:\zabbix\zabbix_agentd.conf" -NewName "zabbix_agentd2.conf"
        $reader = Get-Content "C:\zabbix\zabbix_agentd2.conf"
        $newServers=@(<<<serverIP's go here>>>)

        foreach ($line in $reader) {
        if ($line -match "^server=.*"){
        $line="Server=$newServers"
        }


        $line | Out-File C:\zabbix\zabbix_agentd.conf -Append ascii
        start-service "Zabbix Agent"

        The only hard part is deploying the script to the 90 servers to run unattended and without you logging in to each.

        Comment

        • StephenJ
          Member
          • Dec 2018
          • 44

          #5
          I pared it down to this and it works perfectly. It does need powershell run as administrator to stop and start the services. I may still have to log on manually, but at least I dont have to edit the file manually!


          stop-service "Zabbix Agent"
          $filecontent = Get-Content "C:\Program Files\Zabbix Agent\zabbix_agentd.conf"
          $filecontent -replace 'Server=x.x.x.x','Server=y.y.y.y' | Set-Content "C:\Program Files\Zabbix Agent\zabbix_agentd.conf"
          start-service "Zabbix Agent"

          Comment

          • StephenJ
            Member
            • Dec 2018
            • 44

            #6
            Update 2:

            I am testing this script to connect to multiple servers:

            [string[]]$servers = 'emscaps01,emscaps02' -split ',' #put a list of servers into an array; you can get these however (typically read from a file; in this case splittling a comma separated string)
            $credential = Get-Credential #this will prompt you to enter your account credentials
            Invoke-Command -ComputerName $servers -Credential $credential -ScriptBlock {
            stop-service "Zabbix Agent"
            }

            But it is not liking the user credentials I am supplying even though the user is a local admin on the servers.

            Comment

            • boyemillar
              Member
              Zabbix Certified Specialist
              • Nov 2015
              • 33

              #7
              Hi Stephen,

              Have a look and see if User Account Control is enabled on the servers as this often blocks remote scripts

              Sometimes just disabling the it from the GUI is not enough and a registry hack followed by a reboot is required see below

              x64 Servers - HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ Windows\CurrentVersion\Policies\System\
              x86 Servers - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Policies\System

              Make sure the value of "EnableLUA" = 0

              If it's not UAC then it must be a Powershell executionpolicy issue on the servers

              We use PDQ deploy software which has a basic free version which should be able to push what you want to do

              Comment

              • StephenJ
                Member
                • Dec 2018
                • 44

                #8
                Perfect thanks. Its not the end of the world to log on to the 90 servers and run the powershell script locally. I know that works. Would be nice to do it from one server!

                Ahh EnableLUA is set to 1 I wouldn't be able to disable this on our clients severs. I am running this on one of our test servers at the minute.
                Last edited by StephenJ; 24-01-2019, 14:20.

                Comment

                • boyemillar
                  Member
                  Zabbix Certified Specialist
                  • Nov 2015
                  • 33

                  #9
                  Have a look at PDQ.com... We have a paid for version which gives advanced multi step installs but i'm sure you could use the free version to do what you want... Just provide it a list of the servers and let it run through them

                  Comment

                  • StephenJ
                    Member
                    • Dec 2018
                    • 44

                    #10
                    So I wasn't having much luck with powershell and UAC. So I wrote my own script in VB. This is massively over engineered. I wanted a lot of error checking on each stage. So Steps of script are:

                    Add all servers into a text file
                    Script pings all servers, creates a text file with results
                    All online servers are then copied to another text file
                    From second text file, Services are stopped
                    Config file edited
                    Services started
                    Results outputed to texts files for checks

                    Comment

                    • StephenJ
                      Member
                      • Dec 2018
                      • 44

                      #11
                      Dim strSearchFor,StrResutsFilePath
                      Const ForAppending = 8
                      Const ForReading = 1
                      Const ForWriting = 2

                      StrServerList = "C:\Users\sjohnston\Desktop\servers.txt"
                      StrOnlineFilename = "C:\Users\sjohnston\Desktop\Server Status.txt"
                      StrZabbixFilename = "C:\Users\sjohnston\Desktop\ZabbixServers.txt"
                      StrZabbixConfigResultsFilename = "C:\Users\sjohnston\Desktop\ZabbixConfigResults.tx t"
                      StrZabbixServiceResultsFilename = "C:\Users\sjohnston\Desktop\ZabbixServiceResults.t xt"
                      StrService = "Zabbix Agent"
                      StrSearchFor = "Server=X.X.X.X"

                      '---Main Script----------------------------------------------------------------------
                      Set objFSO=CreateObject("Scripting.FileSystemObject")

                      Set StrServers = objFSO.OpenTextFile(StrServerList)
                      Set StrOnlineStatus = objFSO.OpenTextFile(StronlineFilename, ForAppending, True)
                      Set StrZabbixServersFilename = objFSO.OpenTextFile(StrZabbixFilename, ForAppending, True)

                      WScript.echo "Editing Zabbix Config Files ..."
                      WScript.echo ""
                      WScript.echo "Loadig list of servers"

                      Do Until StrServers.AtEndOfStream
                      StrComputer = StrServers.ReadLine
                      WScript.echo StrComputer
                      Set objShell = WScript.CreateObject("WScript.Shell")
                      Set objExec = objShell.Exec("ping -n 3 -w 1000 " & StrComputer)
                      strOutput = objExec.StdOut.ReadAll
                      If Network_Status(StrIP) then
                      StrOnlineStatus.write StrComputer & VBTAB & "Online" & vbCrLf
                      StrZabbixServersFilename.write StrComputer & vbCrLf
                      Else
                      StrOnlineStatus.write StrComputer & VBTAB & "Offline" & vbCrLf
                      End if
                      Loop
                      StrZabbixServersFilename.close
                      WScript.echo ""
                      WScript.echo "Stopping Zabbix Services"
                      '---Stop Zabbix Services-------------------------------------------------------------
                      Set StrZabbixServersFilename = objFSO.OpenTextFile(StrZabbixFilename)
                      Do Until StrZabbixServersFilename.AtEndOfStream
                      StrComputer = StrZabbixServersFilename.ReadLine
                      Set objWMIService = GetObject("winmgmts:" _
                      & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
                      Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service")
                      For Each objService in colServices
                      If objService.Name = StrService Then
                      If objService.State = "Stopped" Then
                      WScript.Echo StrComputer & " Already stopped"
                      Set StrZabbixServiceFilename = objFSO.OpenTextFile(StrZabbixServiceResultsFilenam e, ForAppending, True)
                      StrZabbixServiceFilename.write StrComputer & vbTab & "Zabbix Service Already Stopped" & vbCrLf
                      StrZabbixServiceFilename.close
                      Else
                      intStop = objService.StopService
                      If intStop = 0 Then
                      WScript.Echo StrComputer & " Zabbix Agent service stopped"
                      Set StrZabbixServiceFilename = objFSO.OpenTextFile(StrZabbixServiceResultsFilenam e, ForAppending, True)
                      StrZabbixServiceFilename.write StrComputer & vbTab & "Zabbix Service Stopped" & vbCrLf
                      StrZabbixServiceFilename.close
                      Else
                      WScript.Echo StrComputer & " Zabbix Agent unable to stop service"
                      Set StrZabbixServiceFilename = objFSO.OpenTextFile(StrZabbixServiceResultsFilenam e, ForAppending, True)
                      StrZabbixServiceFilename.write StrComputer & vbTab & "Unable to start Zabbix Service" & vbCrLf
                      StrZabbixServiceFilename.close
                      End If
                      End If
                      End if
                      Next
                      Loop
                      StrZabbixServersFilename.close
                      WSCript.echo
                      WSCript.echo "Editing Zabix Config Files"

                      '---Edit Config File-----------------------------------------------------------------
                      Set StrZabbixServersFilename = objFSO.OpenTextFile(StrZabbixFilename)
                      Do Until StrZabbixServersFilename.AtEndOfStream
                      StrComputer = StrZabbixServersFilename.ReadLine
                      WScript.echo StrComputer
                      Set objFSO = CreateObject("Scripting.FileSystemObject")
                      StrConfigFilePath = "\" & StrComputer & "\C$\Program Files\Zabbix Agent\zabbix_agentd.conf"
                      Set objFile = objFSO.OpenTextFile(StrConfigFilePath, ForReading)
                      strText = objFile.ReadAll
                      objFile.Close
                      strNewText = Replace(strText, "Server=X.X.X.X", "Server=X.X.X.X")
                      Set objFile = objFSO.OpenTextFile(StrConfigFilePath, ForWriting)
                      objFile.WriteLine strNewText
                      objFile.Close
                      Loop
                      StrZabbixServersFilename.close

                      WSCript.echo
                      WSCript.echo "Checking Zabix Config Files"
                      '---Checking Config File-------------------------------------------------------------
                      Set StrZabbixServersFilename = objFSO.OpenTextFile(StrZabbixFilename, ForReading, True)
                      Do Until StrZabbixServersFilename.AtEndOfStream
                      StrComputer = StrZabbixServersFilename.ReadLine
                      Set objFSO = CreateObject("Scripting.FileSystemObject")
                      StrConfigFilePath = "\" & StrComputer & "\C$\Program Files\Zabbix Agent\zabbix_agentd.conf"
                      Set objFile = objFSO.OpenTextFile(StrConfigFilePath, ForReading)
                      strText = objFile.Readall
                      If inStr(strText,"Server=X.X.X.X") Then
                      WScript.echo StrComputer & " String found"
                      Set StrZabbixConfigFilename = objFSO.OpenTextFile(StrZabbixConfigResultsFilename , ForAppending, True)
                      StrZabbixConfigFilename.write StrComputer & vbTab & "String Found" & vbCrLf
                      StrZabbixConfigFilename.close
                      Else
                      WScript.echo StrComputer & " String not found"
                      Set StrZabbixConfigFilename = objFSO.OpenTextFile(StrZabbixConfigResultsFilename , ForAppending, True)
                      StrZabbixConfigFilename.write StrComputer & vbTab & "String Found" & vbCrLf
                      StrZabbixConfigFilename.close
                      End if
                      objFile.Close
                      Loop
                      StrZabbixServersFilename.close

                      WScript.echo ""
                      WScript.echo "Starting Zabbix Services"
                      '---Start Zabbix Services------------------------------------------------------------
                      Set StrZabbixServersFilename = objFSO.OpenTextFile(StrZabbixFilename)
                      Do Until StrZabbixServersFilename.AtEndOfStream
                      StrComputer = StrZabbixServersFilename.ReadLine
                      Set objWMIService = GetObject("winmgmts:" _
                      & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
                      Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service")
                      For Each objService in colServices
                      If objService.Name = StrService Then
                      If objService.State = "Started" Then
                      WScript.Echo StrComputer & " Zabbix Agennt already started"
                      Set StrZabbixServiceFilename = objFSO.OpenTextFile(StrZabbixServiceResultsFilenam e, ForAppending, True)
                      StrZabbixServiceFilename.write StrComputer & vbTab & "Zabbix Service Already Started" & vbCrLf
                      StrZabbixServiceFilename.close
                      Else
                      intSart = objService.StartService
                      If intStart = 0 Then
                      WScript.Echo StrComputer & " Zabbix Agent started"
                      Set StrZabbixServiceFilename = objFSO.OpenTextFile(StrZabbixServiceResultsFilenam e, ForAppending, True)
                      StrZabbixServiceFilename.write StrComputer & vbTab & "Zabbix Service Started" & vbCrLf
                      StrZabbixServiceFilename.close
                      Else
                      WScript.Echo StrComputer & " Zabbix Agent unable to start service"
                      Set StrZabbixServiceResultsFilename = objFSO.OpenTextFile(StrZabbixServiceResultsFilenam e, ForAppending, True)
                      StrZabbixConfigResultsFilename.write StrComputer & vbTab & "Unablle to start Zabbix Service" & vbCrLf
                      StrZabbixConfigResultsFilename.close
                      End If
                      End If
                      End if
                      Next
                      Loop
                      StrZabbixServersFilename.close
                      WScript.echo
                      WSCript.echo "Script Complete"

                      '---Sub Functions--------------------------------------------------------------------
                      Function Network_Status(StrIP)
                      Set objShell = CreateObject("WScript.Shell")
                      Set objExec = objShell.Exec("ping -n 2 -w 500 " & StrComputer)
                      StrPingResults = LCase(objExec.StdOut.ReadAll)
                      If InStr(StrPingResults, "ttl=") Then
                      Online = True
                      Elseif InStr(StrPingResults, "reply from ::1: time<") Then
                      Online = True
                      Else
                      Online = False
                      End if
                      Network_Status = Online
                      End Function
                      StrOnlineStatus.Close

                      Comment

                      Working...