Hi
I wanted to know if this is zabbix problem or not.
So my script is like this
##SCRIPT
$CheckInstalled = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "zabbix agent*"}
if( $CheckInstalled.IdentifyingNumber -eq "{Product code}")
{write-host Right Version}
Else{
$CheckInstalled = $null
$InstallLocation = "C:\Temporary."
$MSIFile = "zabbix_agent-5.4.2-windows-amd64-openssl.msi"
$exe = "msiexec.exe"
$ZabbixServer = "local.com"
$serveractive = "proxy.com:10051"
$hostFQDN = ([System.Net.Dns]::GetHostByName(($env:computerName))).HostName
#$PSKIDENTITY="<PSK IDENTIFY>"
#$PSKKEY="<PSK KEY>"
$Arguments = "/i $InstallLocation\$MSIFile HOSTNAME=$hostFQDN SERVER=$ZabbixServer SERVERACTIVE=$serveractive ENABLEPATH=TRUE LOGTYPE=file /qn"
$AgentVersion = "5.4.2"
$InstallDestination = ($env:ProgramFiles)+"\Zabbix Agent"
$ZabbixConfig = "zabbix_agentd.conf"
#get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name
$CheckInstalled = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "zabbix agent*"}
#$CheckInstalled = $null
#First Install
If ($null -eq $CheckInstalled){
Start-Process -FilePath $exe -ArgumentList $Arguments -Wait
Start-Sleep -s 10
# Update zabbix_agentd.conf for HOSTMETADATA
$GetFile = Get-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' #| Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadataItem=', 'HostMetadataItem=system.uname' #| Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# 1 - AllowKey=system.run[*]', 'AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' -replace '# HostMetadataItem=' -replace '# LogRemoteCommands=0', 'AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
sc.exe failure 'zabbix agent' reset= "" actions= restart/1200
sc.exe config 'zabbix agent' start= auto
Start-Sleep -s 3
Stop-Service -Name 'Zabbix Agent'
#Set-Service -name 'Zabbix Agent' -StartupType Automatic
Start-Sleep -s 3
#Get-Service -Name 'Zabbix Agent' | Start-Service
Start-Service -name 'Zabbix agent'
}
Start-Service -name "Zabbix*"
#
Start-Sleep -s 5
if ($null -ne $CheckInstalled -and $CheckInstalled.Version -lt $AgentVersion){
$version=$CheckInstalled.IdentifyingNumber
Stop-Service -Name "Zabbix Agent"
#$uninstall="/x $version /qn"
Start-Process msiexec.exe "/x $version /qn /norestart"
Start-Sleep -s 3
Start-Process -FilePath $exe -ArgumentList $Arguments -Wait
$GetFile = Get-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadataItem=' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# LogRemoteCommands=0', 'LogRemoteCommands=AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' -replace '# HostMetadataItem=' -replace '# LogRemoteCommands=0', 'AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
sc.exe config 'zabbix agent' start= auto
Restart-Service -Name 'Zabbix Agent'
Get-Service -Name 'Zabbix Agent' | set-service -StartupType Automatic
}
}
Basically it works with 5.0 and older versions but not anymore with the 5.4
My second problem is that the conf file doesnt add right hostname. etc i have test-test.local.com but unfortunately it write only test-test.
i would be grateful for any help
I wanted to know if this is zabbix problem or not.
So my script is like this
##SCRIPT
$CheckInstalled = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "zabbix agent*"}
if( $CheckInstalled.IdentifyingNumber -eq "{Product code}")
{write-host Right Version}
Else{
$CheckInstalled = $null
$InstallLocation = "C:\Temporary."
$MSIFile = "zabbix_agent-5.4.2-windows-amd64-openssl.msi"
$exe = "msiexec.exe"
$ZabbixServer = "local.com"
$serveractive = "proxy.com:10051"
$hostFQDN = ([System.Net.Dns]::GetHostByName(($env:computerName))).HostName
#$PSKIDENTITY="<PSK IDENTIFY>"
#$PSKKEY="<PSK KEY>"
$Arguments = "/i $InstallLocation\$MSIFile HOSTNAME=$hostFQDN SERVER=$ZabbixServer SERVERACTIVE=$serveractive ENABLEPATH=TRUE LOGTYPE=file /qn"
$AgentVersion = "5.4.2"
$InstallDestination = ($env:ProgramFiles)+"\Zabbix Agent"
$ZabbixConfig = "zabbix_agentd.conf"
#get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name
$CheckInstalled = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "zabbix agent*"}
#$CheckInstalled = $null
#First Install
If ($null -eq $CheckInstalled){
Start-Process -FilePath $exe -ArgumentList $Arguments -Wait
Start-Sleep -s 10
# Update zabbix_agentd.conf for HOSTMETADATA
$GetFile = Get-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' #| Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadataItem=', 'HostMetadataItem=system.uname' #| Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# 1 - AllowKey=system.run[*]', 'AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' -replace '# HostMetadataItem=' -replace '# LogRemoteCommands=0', 'AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
sc.exe failure 'zabbix agent' reset= "" actions= restart/1200
sc.exe config 'zabbix agent' start= auto
Start-Sleep -s 3
Stop-Service -Name 'Zabbix Agent'
#Set-Service -name 'Zabbix Agent' -StartupType Automatic
Start-Sleep -s 3
#Get-Service -Name 'Zabbix Agent' | Start-Service
Start-Service -name 'Zabbix agent'
}
Start-Service -name "Zabbix*"
#
Start-Sleep -s 5
if ($null -ne $CheckInstalled -and $CheckInstalled.Version -lt $AgentVersion){
$version=$CheckInstalled.IdentifyingNumber
Stop-Service -Name "Zabbix Agent"
#$uninstall="/x $version /qn"
Start-Process msiexec.exe "/x $version /qn /norestart"
Start-Sleep -s 3
Start-Process -FilePath $exe -ArgumentList $Arguments -Wait
$GetFile = Get-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# HostMetadataItem=' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
#$GetFile -replace '# LogRemoteCommands=0', 'LogRemoteCommands=AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
$GetFile -replace '# HostMetadata=', 'HostMetadata=Windows' -replace '# HostMetadataItem=' -replace '# LogRemoteCommands=0', 'AllowKey=system.run[*]' | Set-Content -Path "$InstallDestination\$ZabbixConfig"
sc.exe config 'zabbix agent' start= auto
Restart-Service -Name 'Zabbix Agent'
Get-Service -Name 'Zabbix Agent' | set-service -StartupType Automatic
}
}
Basically it works with 5.0 and older versions but not anymore with the 5.4
My second problem is that the conf file doesnt add right hostname. etc i have test-test.local.com but unfortunately it write only test-test.
i would be grateful for any help