Skip to content

Instantly share code, notes, and snippets.

@rhavenn
Created April 12, 2016 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhavenn/3ab30f081c0ed4f450c54a7a768407af to your computer and use it in GitHub Desktop.
Save rhavenn/3ab30f081c0ed4f450c54a7a768407af to your computer and use it in GitHub Desktop.
Zabbix install script
### Install_BaseConfig_DEV
$DSC_ConfigName = 'Install_BaseConfig_DEV';
Configuration $DSC_ConfigName
{
#load DSC resources (Get-DscResource shows all available Modules and names)
Import-DSCResource -ModuleName PSDesiredStateConfiguration -Name Script
#run all configurations
###
###ZABBIX SETUP
###START
#install zabbix agent
File Install_Zabbix_Agent
{
CheckSum = "SHA-1";
DestinationPath = "C:\Program Files\Zabbix\";
Ensure = "Present";
Force = $true;
MatchSource = $true;
Recurse = $true;
SourcePath = "\\networkpath\Installers\Zabbix\Agent\3.0.0\win64\";
Type = "Directory";
}
#install zabbix config
File Install_Zabbix_Agent_Config
{
CheckSum = "SHA-1";
DependsOn = "[File]Install_Zabbix_Agent"; #depends on the agent install
DestinationPath = "C:\ProgramData\Zabbix\zabbix_agentd.conf";
Ensure = "Present";
Force = $true;
MatchSource = $true;
SourcePath = "\\networkpath\Installers\Zabbix\Agent\conf\default_zabbix_agentd.win.conf";
Type = "File";
}
#install zabbix agent as a service
Script Install_Zabbix_Agent_Service
{
#depends on config file
DependsOn = "[File]Install_Zabbix_Agent_Config";
#hash table; values returns when Get-DscConfiguration is called
GetScript = {
if ( Get-Item 'C:\Program Files\Zabbix\zabbix_agentd.exe' )
{
return @{ result = $True }
}else
{
return @{ result = $False }
}
}
#check to see if service is set
TestScript =
{
If (Get-Service | Where-Object {$_.Name -eq "Zabbix Agent"} )
{
#service installed. return $false
return $false;
}else{
#service is not installed.
return $true;
}
}
SetScript =
{
#run zabbix install service command
Invoke-Command -ScriptBlock { & 'C:\Program Files\Zabbix\zabbix_agentd.exe' --config C:\ProgramData\Zabbix\zabbix_agentd.conf --install }
}
}
#install zabbix agent as a service
Script DeleteFile
{
#hash table; values returns when Get-DscConfiguration is called
GetScript = {
if ( Get-Item 'C:\Program Files\Zabbix\service_install.ps1' )
{
return @{ result = $True }
}else
{
return @{ result = $False }
}
}
#check to see if service is set
TestScript =
{
return $true;
}
SetScript =
{
#run zabbix install service command
Remove-Item 'C:\Program Files\Zabbix\service_install.ps1' -Force
}
}
###END
###ZABBIX SETUP
###
}
#call the config function
Install_BaseConfig_DEV
#rename the MOF
#it's "localhost" by default due to this applying to all systems
Move-Item .\$DSC_ConfigName\localhost.mof .\$DSC_ConfigName\$DSC_ConfigName.mof
#generate a checksum
New-DSCCheckSum -ConfigurationPath .\$DSC_ConfigName -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment