ZABBIX Forums  

Go Back   ZABBIX Forums > Zabbix Discussions and Feedback > Zabbix Cookbook

Reply
 
Thread Tools Display Modes
  #11  
Old 07-03-2008, 21:03
Mikrodots Mikrodots is offline
Member
 
Join Date: Mar 2008
Posts: 37
Default Doh!

Thanks Alexei!

I wish I found that yesterday.

Anyway, my scripting needed some dusting off.

Reply With Quote
  #12  
Old 10-03-2008, 18:04
Mikrodots Mikrodots is offline
Member
 
Join Date: Mar 2008
Posts: 37
Default Install from login script

Hi Alexei,

I did check out the win32floppy install but it does not completely do what I need.

I want to run an automated Windows installation from a batch logon script located on a UNC path. The script will run every time a user logs on.

The script must:
  • Check if the Zabbix Agent is installed
  • Install the agent if it is not already installed
  • If installation is needed check for 64 bit OS or 32 to install the correct agent
  • If the agent is installed, make sure it is running, if not, start it

Is there something already available that does this?

Thanks,

Mikrodots
Reply With Quote
  #13  
Old 03-04-2008, 08:20
NOB NOB is offline
Senior Member
Zabbix Certified Specialist
 
Join Date: Mar 2007
Location: Berne, Switzerland
Posts: 447
Default

Quote:
Originally Posted by Mikrodots View Post
Hi Alexei,

I did check out the win32floppy install but it does not completely do what I need.

I want to run an automated Windows installation from a batch logon script located on a UNC path. The script will run every time a user logs on.

The script must:
  • Check if the Zabbix Agent is installed
  • Install the agent if it is not already installed
  • If installation is needed check for 64 bit OS or 32 to install the correct agent
  • If the agent is installed, make sure it is running, if not, start it

Is there something already available that does this?

Thanks,

Mikrodots
Look at this thread in this forum

What is left as an exercise to the reader is the check whether
"ZABBIX Agent" is running, e.g. net start | find "ZABBIX Agent"

HTH,

Norbert.
Reply With Quote
  #14  
Old 10-09-2010, 12:46
Moumita Moumita is offline
Junior Member
 
Join Date: Sep 2010
Posts: 1
Unhappy

Quote:
Originally Posted by DavidS View Post
put the zabbix windows agent exe file on a file share on your network.

Then create a batch file on the same file share like name it installagent.bat or something like that. Installing agent now consists of just navigating to the file share and running the batch file, from each windows box.

installagent.bat:
@echo off
echo copying exe

net use y: \\server\fileshare
xcopy Y:\path\to\exe\zabbixw32.exe c:\
net use y: /delete


echo creating config file

echo Server=zabbix_server_ip_address > c:\zabbix_agentd.conf
echo Hostname=%COMPUTERNAME% >> c:\zabbix_agentd.conf
echo StartAgents=5 >> c:\zabbix_agentd.conf
echo DebugLevel=3 >> c:\zabbix_agentd.conf
echo PidFile=/var/tmp/zabbix_agentd.pid >> c:\zabbix_agentd.conf
echo LogFile=/tmp/zabbix_agentd.log >> c:\zabbix_agentd.conf
echo Timeout=3 >> c:\zabbix_agentd.conf

echo installing service
cd ../../../..
c:\zabbixw32.exe install

echo start service?
pause

net start zabbixagentdw32

can you please describe in details ....How to install zabbix windows agent....
Reply With Quote
  #15  
Old 07-10-2011, 04:20
frankcheong frankcheong is offline
Member
 
Join Date: Oct 2009
Posts: 67
Default

Actually there are tutorial outside about installation of zabbix agentd on windows machine.

http://www.packtpub.com/article/moni...ith-zabbix-1.8
Reply With Quote
  #16  
Old 20-10-2011, 14:12
emil@exoconsult emil@exoconsult is offline
Junior Member
 
Join Date: Oct 2011
Posts: 4
Default Determining windows architecture

Quote:
Originally Posted by Mikrodots View Post
Still testing but so far so good...

Code:
echo off
ECHO.

REM Mike Doherty 
REM Mikrodots, Inc.
REM http://www.mikrodots.com

REM Zabbix Server Address

REM UNC Path to Zabbix Agent installation files
set FilePath64="\\myserver\zabbix\win64\zabbix_agentd.exe"
set FilePath32="\\myserver\zabbix\win32\zabbix_agentd.exe" 

REM Local Variables
set service="ZABBIX Agent"
set SUCCESS="Successfully"
REM I haven't tested this on a 64 bit OS yet
set qry="HKLM\System\CurrentControlSet\Services\Zabbix Agent"

ECHO ---------- Start Zabbix Agent Script...
ECHO.

:IsServiceInstalled
ECHO.
ECHO Is %service% Installed?
reg query %qry% | find /I %service% >NUL
ECHO  If Zero the service is Installed:%ERRORLEVEL%
 If NOT ERRORLEVEL 1 (
  ECHO   YES, %service% Is Installed
  GOTO IsServiceRunning
  ) ELSE (
	 ECHO NO, %service% Is NOT Installed
	 GOTO InstallService
	 )
GOTO END

:IsServiceRunning
ECHO.
ECHO Is %service% Running?
net start | find /I %service% >NUL 
ECHO  If Zero %service% is Running:%ERRORLEVEL% 
 If NOT ERRORLEVEL 1 (
   ECHO   YES, %service% IS Running
   ) ELSE (
   	  ECHO ----------- NO, %service% IS NOT Running -----------------
   	  GOTO StartService
	  )
GOTO END

:StartService
ECHO.
ECHO Try to Start %service%
net start %service% | FIND /I %SUCCESS% >NUL
ECHO  If Zero the %service% started %ERRORLEVEL%
 If NOT ERRORLEVEL 1 ( 
   echo   YES %service% Started Successfully
   ) ELSE ( 
	  ECHO ------------!!!!! %service% DID NOT START !!!!!--------------
	  )
GOTO END

:GetInstallFilePath
ECHO.
REM 32Bit or 64 Bit?
REM Could use a better test, this will fail without a C: drive
if exist "C:\Program Files (x86)" (
  set FilePath=%FilePath64%
  ) else (
	  set FilePath=%FilePath32%
	  )
ECHO Path to zabbix_agentd.exe:  %FilePath%

REM Verify that the installation file exists
XCOPY  %FilePath% /L | find /I %FilePath%  >NUL 
ECHO  If Zero %FilePath% Exists: %ERRORLEVEL% 
 If NOT ERRORLEVEL 1 (
   ECHO   YES, %FilePath% Exists
   GOTO END  REM InstallService
   ) ELSE (
   	  ECHO %FilePath% 
	  ECHO ------------IS NOT VALID -----------------
	  ECHO -------------- EXITING -------------------
   	  GOTO END
	  )
GOTO END

:InstallService
ECHO.
REM Change working directory
CD %SystemDrive%\
REM Make sure we're on the right partition
%SystemDrive%

ECHO Copying %FilePath% To %SystemDrive%
xcopy /F /Y /R %FilePath%

ECHO Writing zabbix_agentd.conf for %COMPUTERNAME%.%USERDNSDOMAIN%
ECHO Server=1.2.3.4 > zabbix_agentd.conf
ECHO ServerPort=10050 >> zabbix_agentd.conf
ECHO Hostname=%COMPUTERNAME%.%USERDNSDOMAIN% >> zabbix_agentd.conf
ECHO ListenPort=10050 >> zabbix_agentd.conf
ECHO StartAgents=5 >> zabbix_agentd.conf
ECHO DebugLevel=3 >> zabbix_agentd.conf
ECHO LogFile= %SystemDrive%\zabbix_agentd.log >> zabbix_agentd.conf
ECHO Timeout=5 >> zabbix_agentd.conf

ECHO Installing %service% as a service
%SystemDrive%\zabbix_agentd.exe -i -c %SystemDrive%\zabbix_agentd.conf
ECHO If Zero the %service% Installed Successfully: %ERRORLEVEL%
 If ERRORLEVEL == 0 ( 
   ECHO   YES, %service% Installed Successfully
   GOTO IsServiceRunning
   ) ELSE ( 
	  ECHO ------------!!!!! %service% Installation FAILED !!!!!--------------
	  GOTO END
	  )
ECHO Finished Installing Zabbix Agent!

GOTO END

:END
ECHO.
ECHO The Script has finnished running!
Only tested this on a 32 bit Vista system so far...

I'd like to get some feedback from anyone who tests this.

Thanks,

Mikrodots
There is an elegant way of finding the OS architecture (32 or 64 bit) by using

wmic OS get OSArchitecture | find /I "64-bit"
if not errorlevel 1 (set FilePath=%FilePath64%
) else (
set FilePath=%FilePath32%
)
ECHO Path to zabbix_agentd.exe: %FilePath%
Reply With Quote
  #17  
Old 21-10-2011, 14:41
emil@exoconsult emil@exoconsult is offline
Junior Member
 
Join Date: Oct 2011
Posts: 4
Lightbulb ZABBIX (RE)Install Script

Hi All

I've made my own version of the install script originally posted here.
This script stops the service, uninstalls the agent and then installs and starts the new version of the agent from the server. It also adds a firewall rule (windows 7 / server 2008) and has a little more sophisticated way of telling the architecture.

An install directory is also made an option and it supports installs with proxy as well.

Let me hear what you think.

/Emil



@echo off
ECHO.


REM ***** Parameters START *****

REM UNC Path to Zabbix Agent installation files
set FilePath64=\\myserver\zabbixinstall\win64\zabbix_a gentd.exe
set FilePath32=\\myserver\zabbixinstall\win32\zabbix_a gentd.exe


REM Agent configuration
REM ----- IMPORTANT ----- Set proxyip to NONE if no proxy is used
set proxyip=0.0.0.0
set serverip=0.0.0.0
set listenport=10050
set serverport=10051
set InstallDir=ZabbixAgent

REM Local Variables
set service="Zabbix Agent"
set SUCCESS="Successfully"
set qry="HKLM\System\CurrentControlSet\Services\Zabbix Agent"

REM ***** Parameters END *****

ECHO ---------- Start Zabbix Agent (Re)Install Script...
ECHO.

:IsServiceInstalled
ECHO.
ECHO Is %service% Installed?
reg query %qry% | find /I %service% >NUL
If NOT ERRORLEVEL 1 (
ECHO %service% Is Installed
GOTO IsServiceRunning
) ELSE (
ECHO %service% Is NOT Installed
GOTO GetInstallFilePath
)
GOTO END

:IsServiceRunning
ECHO.
ECHO Is %service% Running?
net start | find /I %service% >NUL
If NOT ERRORLEVEL 1 (
ECHO %service% IS Running
GOTO StopService
) ELSE (
ECHO %service% is not running
GOTO RemoveService
)
GOTO END

:StopService
ECHO.
ECHO Try to Stop %service%
net stop %service% >NUL
If NOT ERRORLEVEL 1 (
echo %service% Stopped Successfully
GOTO RemoveService
) ELSE (
ECHO ------------!!!!! %service% DID NOT STOP !!!!!--------------
)
GOTO END

:RemoveService
ECHO.
REM Change working directory and partition and create InstallDir if it does not exist
if not exist %SystemDrive%\%InstallDir%\. mkdir %SystemDrive%\%InstallDir%
CD %SystemDrive%\%InstallDir%
%SystemDrive%

REM Remove Installation
ECHO Remove %service% installation
echo Server=%server% >zabbix_agentd.conf
ECHO Copying %FilePath% To %SystemDrive%\%InstallDir%
xcopy /F /Y /R %FilePath%
%SystemDrive%\%InstallDir%\zabbix_agentd.exe --uninstall -c %SystemDrive%\%InstallDir%\zabbix_agentd.conf
If ERRORLEVEL == 0 (
ECHO %service% Uninstalled Successfully!
GOTO GetInstallFilePath )
ELSE
(
ECHO %Service Uninstall NOT successful!
GOTO END
)
GOTO END

:GetInstallFilePath
ECHO.
REM 32Bit or 64 Bit?

wmic OS get OSArchitecture | find /I "64-bit"
if not errorlevel 1 (set FilePath=%FilePath64%
ECHO 64 Bit Operating System - using %FilePath%
) else (
set FilePath=%FilePath32%
ECHO 32 Bit Operating System - using %FilePath%
)

REM Verify that the installation file exists
XCOPY %FilePath% /L /Y | find /I "%FilePath%" >NUL
If NOT ERRORLEVEL 1 (
GOTO InstallService
) ELSE (
ECHO %FilePath%
ECHO ------------IS NOT VALID -----------------
ECHO -------------- EXITING -------------------
GOTO END
)
GOTO END

:InstallService
ECHO.
REM Change working directory and partition and create InstallDir if it does not exist
if not exist %SystemDrive%\%InstallDir%\. mkdir %SystemDrive%\%InstallDir%
CD %SystemDrive%\%InstallDir%
%SystemDrive%

if exist %systemdrive%\%InstallDir%\zabbix_agentd.exe del /Q %systemdrive%\%InstallDir%\zabbix_agent.exe
ECHO Copying %FilePath% To %SystemDrive%\%InstallDir%
xcopy /F /Y /R %FilePath%


ECHO Writing Configuration File for %COMPUTERNAME%.%USERDNSDOMAIN%
IF NOT %proxyip%=="NONE" (ECHO Server=%proxyip%,%serverip% > zabbix_agentd.conf
) ELSE (
ECHO Server=%serverip% >zabbix_agentd.conf
)
ECHO ServerPort=%serverport% >> zabbix_agentd.conf
ECHO Hostname=%COMPUTERNAME%at%USERDNSDOMAIN% >> zabbix_agentd.conf
ECHO ListenPort=%listenport% >> zabbix_agentd.conf
ECHO StartAgents=5 >> zabbix_agentd.conf
ECHO DebugLevel=3 >> zabbix_agentd.conf
ECHO LogFile= %SystemDrive%\%InstallDir%\zabbix_agentd.log >> zabbix_agentd.conf
ECHO Timeout=5 >> zabbix_agentd.conf

ECHO Installing %service% as a service
%SystemDrive%\%InstallDir%\zabbix_agentd.exe -i -c %SystemDrive%\%InstallDir%\zabbix_agentd.conf
If ERRORLEVEL == 0 (
ECHO %service% Installed Successfully
GOTO StartService
) ELSE (
ECHO ----- %service% Installation FAILED -----
GOTO END
)

GOTO END

:StartService
ECHO.
ECHO Adding rule to firewall...
netsh advfirewall firewall add rule name=%service% protocol=TCP dir=in localport=%listenport% action=allow
echo.
ECHO Try to Start %service%
net start %service% >NUL
If NOT ERRORLEVEL 1 (
echo %service% Started Successfully
) ELSE (
ECHO ------------!!!!! %service% DID NOT START !!!!!--------------
)
GOTO END

:END
ECHO.
ECHO The Script has finished running!
Reply With Quote
  #18  
Old 02-12-2011, 09:26
Voxie Voxie is offline
Junior Member
 
Join Date: Jul 2009
Posts: 12
Default My Version.

If have build also my own script:


1) First i detect if its a reinstall of a new install.
2) Then I check if its a 32 of 64 bit machine.
3) Then we ask how the machine is called in Zabbix
4) Then we ask which proxy is going to monitor the machine.
5) Then we check if the zabbix server is able to connect to the agent. (agent.php on the zabbix server)

Zabbix.cmd:
Code:
@ECHO OFF

CLS


NET START | FIND "Zabbix Agent">NUL
IF "%ERRORLEVEL%"=="1" GOTO Detect
IF "%ERRORLEVEL%"=="0" GOTO Reinstall

:Reinstall
 NET STOP "Zabbix Agent"
 SC DELETE "Zabbix Agent"
 IF EXIST C:\Zabbix\ (
  RMDIR /S /Q C:\Zabbix\
  CLS
  GOTO :Detect
 )

:Detect
IF "%PROCESSOR_ARCHITECTURE%" == "x86" (
 GOTO x86
)
IF "%PROCESSOR_ARCHITECTURE%" == "i86" (
 GOTO x86
)
IF "%PROCESSOR_ARCHITECTURE%" == "x64" (
 GOTO x64
)
IF "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
 GOTO x64
)
IF "%PROCESSOR_ARCHITECTURE%" == "amd64" (
 GOTO x64
)

:x86
 
  set /p answer=What is the hostname in Zabbix
 ECHO Which proxy is monitoring the server ? 
 ECHO .
 ECHO .
 set /p answer2=(proxy ip):
 MKDIR C:\Zabbix\
 ECHO Server=%answer2%, server > C:\Zabbix\zabbix_agentd.conf
 ECHO EnableRemoteCommands=1 >> C:\Zabbix\zabbix_agentd.conf
 ECHO Hostname=%answer% >> C:\Zabbix\zabbix_agentd.conf
 ECHO StartAgents=32 >> C:\Zabbix\zabbix_agentd.conf
 COPY \\10.208.60.61\install\x86\*.* C:\Zabbix\
 GOTO Install

:x64
 set /p answer=What is the hostname in Zabbix
 ECHO Which proxy is monitoring the server ? 
 ECHO .
 ECHO .
 set /p answer2=(proxy ip):
 MKDIR C:\Zabbix\
 ECHO Server=%answer2%, server > C:\Zabbix\zabbix_agentd.conf
 ECHO EnableRemoteCommands=1 >> C:\Zabbix\zabbix_agentd.conf
 ECHO Hostname=%answer% >> C:\Zabbix\zabbix_agentd.conf
 ECHO StartAgents=32 >> C:\Zabbix\zabbix_agentd.conf
 COPY \\10.208.60.61\install\x64\*.* C:\Zabbix\
 GOTO Install

:Install
 CLS
 C:\Zabbix\zabbix_agentd.exe -i --config C:\Zabbix\zabbix_agentd.conf
 C:\Zabbix\zabbix_agentd.exe --config C:\Zabbix\zabbix_agentd.conf -s
 GOTO Check

:Check
 ECHO START iexplore http://<server ip>/screen/agent.php
 GOTO End

:End
screen/agent.php
PHP Code:
<?PHP
error_reporting
(0);

if((isset(
$_GET['ip'])) && (!empty($_GET['ip'])))
{
 
$to fopen("hosts.log""a");
 if(
fsockopen($_GET['ip'], 10050))
 {
  
fwrite($to"\nOK: ".$_GET['ip']);
  
$style "border : 1px solid #39C300; color : #39C300; padding-left : 25px; background-image:url(http://10.208.60.61/screen/images/ok.png); background-repeat : no-repeat;";
  PRINT 
'<div style="text-align : center; color : #39C300;">De agent is succesvol ge´nstalleerd!</div>';
 } else
 {
  
fwrite($to"\nERROR: ".$_GET['ip']);
  
$style "border : 1px solid #FF0000; color : #FF0000;";
  PRINT 
'<div style="text-align : center; color : #FF0000;">Controleer of de Zabbix service is gestart en/of TCP poort 10050 niet geblokkeerd wordt door een firewall.</div>';
 }
 
fclose($to);
} else
{
 
$style "border : 1px solid #000;";
}
?>
<form method="get" action="" style="text-align : center;">
 <input type="text" name="ip" style="width : 150px; <?PHP PRINT $style?>" value="<?PHP if((isset($_GET['ip'])) && (!empty($_GET['ip']))){ PRINT $_GET['ip']; } else { PRINT $_SERVER['REMOTE_ADDR']; } ?>" /> <input type="submit" value="Controleer" />
</form>

Last edited by Voxie; 02-12-2011 at 09:36. Reason: typo
Reply With Quote
  #19  
Old 02-12-2011, 09:32
emil@exoconsult emil@exoconsult is offline
Junior Member
 
Join Date: Oct 2011
Posts: 4
Default Nice

Nice job.

Good inspiration to improve my own script
Reply With Quote
  #20  
Old 30-04-2012, 21:19
natewlew natewlew is offline
Junior Member
 
Join Date: Apr 2012
Posts: 4
Default

Thanks for the script. I just wanted to post the changes I made. This also helps with finding the network interface name and adds it to the config as NetIn and NetOut.

The one that comes with Zabbix is a little outdated but a good starting point?

Code:
@ECHO OFF

REM Config Settings
SET my_zabbix_share=\\ServerNameOrIP\Share\zabbix_clients\bin\
SET my_zabbix_install_path=C:\Zabbix\
SET my_zabbix_config=C:\Zabbix\zabbix_agentd.conf
SET temp_notepad_file=c:\findinterface.txt

CLS


NET START | FIND "Zabbix Agent">NUL
IF "%ERRORLEVEL%"=="1" GOTO Pre-Install
IF "%ERRORLEVEL%"=="0" GOTO Reinstall

:Reinstall
 NET STOP "Zabbix Agent"
 SC DELETE "Zabbix Agent"
 IF EXIST %my_zabbix_install_path% (
  RMDIR /S /Q %my_zabbix_install_path%
  CLS
  GOTO :Pre-Install
 )

:Pre-Install

 REM Open notepad with possible config values
 ECHO "View the Text File that opens for Config Options."
 ECHO Hostname is? > %temp_notepad_file%
 hostname >> %temp_notepad_file%
 ECHO . >> %temp_notepad_file%
 ECHO This could be your Network Interface(s)? >> %temp_notepad_file%
 typeperf -qx | find "Network Interface" >> %temp_notepad_file%
 start notepad.exe %temp_notepad_file%
 ECHO .

 REM Get the values from the user
 set /p answer=What is the hostname in Zabbix: 
 ECHO .
 set /p answer2=Server/Proxy IP: 
 Echo .
 set /p nicname=Host Network Card Name:

 REM Write the values to the config file
 MKDIR %my_zabbix_install_path%
 ECHO LogFile=%my_zabbix_install_path%zabbix_agentd.log > %my_zabbix_config%
 ECHO Server=%answer2% >> %my_zabbix_config%
 ECHO EnableRemoteCommands=1 >> %my_zabbix_config%
 ECHO Hostname=%answer% >> %my_zabbix_config%
 ECHO PerfCounter = NetIn,"\Network Interface(%nicname%)\Bytes Received/sec",60 >> %my_zabbix_config%
 ECHO PerfCounter = NetOut,"\Network Interface(%nicname%)\Bytes Sent/sec",60 >> %my_zabbix_config%

 REM Cleanup the notepad file. User doesn't have to close the file.
 set /p nothing=Close Notepad and Press Enter:
 DEL %temp_notepad_file%

 GOTO :Detect


:Detect
IF "%PROCESSOR_ARCHITECTURE%" == "x86" (
 GOTO x86
)
IF "%PROCESSOR_ARCHITECTURE%" == "i86" (
 GOTO x86
)
IF "%PROCESSOR_ARCHITECTURE%" == "x64" (
 GOTO x64
)
IF "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
 GOTO x64
)
IF "%PROCESSOR_ARCHITECTURE%" == "amd64" (
 GOTO x64
)

:x86
 COPY %my_zabbix_share%win32\*.* %my_zabbix_install_path%
 GOTO Install

:x64
 COPY %my_zabbix_share%win64\*.* %my_zabbix_install_path%
 GOTO Install

:Install
 CLS
 %my_zabbix_install_path%zabbix_agentd.exe -i --config %my_zabbix_config%
 %my_zabbix_install_path%zabbix_agentd.exe --config %my_zabbix_config% -s

:End
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:59.