Deploying NXLog to several machines at once can be done with a few simple lines of powershell!
What will happen?
- The NXLog MSI installer, the installation PS script, and a default NXLog config file will be copied to designated hosts
- The installer script will be executed and the NXLog service will be started
1. Create a directory called C:\temp\unomaly\ on the machine from which you intend to deploy NXLog. Put the following files and config in that folder.
2. Download the latest MSI package of NXLog
3. Create a file containing a list of hosts to which we want to install NXLog on, let's call it hosts.txt, its contents should similar to the below
4. Create a default nxlog.conf - make sure to replace the necessary variables with the correct values for your environment
define ROOT C:\Program Files (x86)\nxlog Moduledir %ROOT%\modules CacheDir %ROOT%\data Pidfile %ROOT%\data\nxlog.pid SpoolDir %ROOT%\data LogFile %ROOT%\data\nxlog.log SuppressRepeatingLogs FALSE <Extension syslog> Module xm_syslog </Extension> <Input eventlog> Module im_msvistalog </Input> <Input logfile> InputType LineBased Module im_file File 'C:\Path\To\file.log' PollInterval 10 DirCheckInterval 10 CloseWhenIdle TRUE </Input> <Output unomaly> Module om_udp Host [UNOMALY INSTANCE HOSTNAME] Port 5514
Exec $Hostname = hostname(); Exec to_syslog_bsd(); </Output> <Route r_unomaly> Path eventlog, logfile => unomaly </Route>
5. Create a file called install_nxlog.ps1 - this will be executed on the hosts and perform the installation of NXLog
msiexec /i "C:\temp\nxlog.msi" /quiet
6. Create remote_install_nxlog.ps1, the script which will loop over the hosts in the hosts.txt file and deploy NXLog to them. Replace the msi name with the one you downloaded.
foreach ($i in Get-Content "C:\temp\unomaly\hosts.txt")
Copy-Item "C:\temp\unomaly\nxlog-ce-2.9.1716.msi" -Destination "\\$i\c$\temp\nxlog.msi";
Copy-Item "C:\temp\unomaly\install_nxlog.ps1" -Destination "\\$i\c$\temp\install_nxlog.ps1";
Invoke-Command -ComputerName $i -FilePath "\\$i\c$\temp\install_nxlog.ps1";
Start-Sleep -s 120;
Copy-Item "C:\temp\unomaly\nxlog.conf" -Destination "\\$i\c$\Program Files (x86)\nxlog\conf";
Get-Service -Name "nxlog" -ComputerName $i | Set-Service -Status Running
Execute the script we created in step 6!