New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Powershell Notification Parameters

Votes:

0

Your Vote:

Up

Down

I'm trying to use a powershell Script in a Notification, but I can't get it to work correctly with parameters, that are Placeholders.

The Script I'm trying to run just writes a file containing the parameters and some other info.

I tried with standard parameters: "%sitename %device %name %status %down %message" -> I get no file at all, but as soon as I remove the %sitename, I get a file, but the other parameters aren't resolved, just passed as string %device, %name etc. (In the Notification Test) - which is normal I suppose, since there is no device that sent the event.

When I test this with a real device though ( I set the new Notification on a Ping sensor and then killed the Network Connection) I get no file again.

This is the Script:

param(
    [string]$SiteName = "N/A",
    [string]$Device = "N/A",
    [string]$Name = "N/A",
    [string]$Status = "N/A", 
    [string]$Down = "N/A",
    [string]$Message = "N/A"
    )


$numbers = @(0000)
$outpath = "\\server\sms\outgoing\"
foreach ($number in $numbers){
    $date = Get-Date
    $outfile = $outpath + $date.ToString("hhmmssfff")
    $outstr = "To: $number" + [System.Environment]::NewLine + [System.Environment]::NewLine

    $outstr= $outstr +"$SiteName $Device $Name $Status $Down $Message"
    $outstr | Out-File -FilePath $outfile -Encoding ascii
}

exit 0

notification parameter powershell prtg

Created on May 23, 2014 12:16:11 PM by  treinhardt (10) 1



3 Replies

Votes:

0

Your Vote:

Up

Down

Hello,

thank you very much for your KB-Post. May I ask, how exactly do you pass on the parameters then in PRTG? Can you please try encapsulating them individually with either " or ' ?
Does this help?

best regards.

Created on May 27, 2014 10:10:35 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Your Vote:

Up

Down

My script is still having trouble, even after passing parameters like this:

   '%hostname' '%linuxuser' 'linuxpassword'

and like this:

   "%hostname" "%linuxuser" "%linuxpassword"

It completes the task if I hard-code the values, but I can't seem to get the parameters passed correctly from PRTG.

Script:

param(
    [string]$hostName= "N/A",
    [string]$lxuser= "N/A",
    [string]$lxpasswd= "N/A",
    )
$creds = New-Object System.Management.Automation.PSCredential($lxuser,$lxpasswd)

New-SSHSession -ComputerName $hostName -Credentials $creds -AcceptKey $TRUE
Invoke-SSHCommand -Index 0 -Command "service apache2 start"
Remove-SSHSession -Index 0

Created on Oct 15, 2015 9:31:24 PM by  Jacob (0)

Last change on Oct 16, 2015 6:43:43 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Please be aware that we can only provide very limited support with custom scripting. We recommend to build logging output into your script, so that it writes log entries with each step. This should help to identify the cause. It may be an account issue here if it runs fine under your account on CMD, but not with the "LOCAL SYSTEM"-account of the Probe Service.

Created on Oct 16, 2015 11:58:17 AM by  Torsten Lindner [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.