Scripts

Nagios Cross-Platform Agent silent install with powershell

I'm making this post post because it is easier that trying to figure out how to reply properly on reddit.

original script from Mr Redditguy

first you need the files. download from here.

https://www.nagios.org/ncpa/#downloads

The version in used is here https://assets.nagios.com/downloads/ncpa3/ncpa-3.0.1.exe

here's the script

# Generate API Token
$password = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 26 | ForEach-Object {[char]$_})
$hostname = $Env:COMPUTERNAME.ToUpper()
$ncpaArgs = "/S /TOKEN='$password' /NRDPURL='URL' /NRDPTOKEN='NRDP_T0k3n' /NRDPHOSTNAME='$hostname'"
md -Force c:\logs
md -Force c:\temp
$process = Start-Process -NoNewWindow -PassThru -FilePath $PSScriptRoot\ncpa-3.0.1.exe -ArgumentList $ncpaArgs
$dummy = $process.Handle # Cache the handle
$process.WaitForExit()
Add-Content -Path "C:\Logs\NCPAClient Installed.txt" "$('{0:dd/MM/yyyy}' -f (Get-Date)) NCPA Exit code = $($process.ExitCode)"
#Get Ip Address
$IPadr =((ipconfig | findstr [0-9].\.)[0]).Split()[-1]
#$IPadr
$Error.Clear()
try {
$filePath = "C:\temp\NCPAServerData.txt"
$Row = [PSCustomObject]@{
'host_name' = $hostname
'address' = $IPadr
'ncpa_community_string' = $password
}
$Row | Export-Csv -NoTypeInformation -Append -force -Path $filePath
}
catch {
Add-Content -Path "C:\Logs\NCPAClient_Error.log" "$('{0:dd/MM/yyyy}' -f (Get-Date)) Error writing server data $Error[0]"
}
# Write log file for detection method
Add-Content -Path "C:\Logs\NCPAClient Installed.txt" "$('{0:dd/MM/yyyy}' -f (Get-Date)) Installation Complete"

  1. start out by generating a random password (you could just make up any password here if you wanted)

  2. then get your current computername

  3. then the arguments actually needed for the installer. silent install commands here

  4. create some folders logs and temp these aren't needed for the install, but used for logging purposes incase they didn't already exist

  5. install the application and wait for the process to exist before writing the exist code to the logs.

  6. write the config information to a log

  7. then install completed.

Now set it up as an application in SCCM in the typical fashion.

right-click on application node -> create application ->manually specify the application information (next)-> give it a name and other info (next)-> give it software center info (next) -> add deployment type -> type: script installer(next)->name(next)->

the important bits

content location = your content location?

Install Program = Powershell.exe -file "Nagios_NCPA_3.0.1.0_R00.ps1"

Uninstall Program = "C:Program FilesNagiosNCPAuninstall.exe" /AllUsers /S

Add file system detection method

Path = C:Program FilesNagiosNCPA

Filename = uninstall.exe

let's deploy the app and see if it installs

first we see the files shows up from the detection method.

test the login based on the information saved under c:tempNCPAServerData.txt

open a browser and goto https://localhost:5693

Nagios NCPA PowerShell SCCM silent install monitoring
✉

Get new articles in your inbox

SCCM guides, AI tools, automation tips — sent when published. No spam.

Keep reading

Comments