There is a little magic to make PowerShell counters in PRTGafter the counter is created it may turn out that it does not give out numbers, although everything is fine in the console or during manual start. And the fact is that PRTG runs scripts from under "itself", it can:
')
- not have access rights
- running scripts in the system may be prohibited
- Script launch in x86 version may be prohibited, and in x64 allowed
You need to start with the last two points. You can check the script startup policy with the command
Get-ExecutionPolicy
If she returned Restricted, then you need to allow running scripts on this system by running the command from the administrative console.
Set-ExecutionPolicy Unrestricted
For those who want security - sign scripts even with a local certificate and install the AllSigned policy.
After installing the script launch policy, make sure that everything is correct, for those who have a 32-bit version of PowerShell, install the policy in it, too, since PRTG can try to run your script from the 32-bit version. (More precisely, it will do so if there is a PowerShell x86 version), the launch policies are different, and if you install it in 64-bit, you can forget that in 32 it remains. Just run under the admin Powershell x86 and make the same settings in it.
The problem of rights is solved more simply - we set the rights to everyone and if it works, it means that it is not enough. If the script has an alternative ntfs in the properties, then it should be removed
12345:Ok # , 12345 :Ok
1000 :To low 2000 :Ok 5000 :To high
# 1 30 # $FileName = 'C:\PRTG\sales_today.txt' # $ErrorActionPreference = 'SilentlyContinue' if ((Test-Path $FileName) -eq $false) { Write-Host "0 :Error" } else { $Val = Get-Content $FileName | select -First 1 # , # ( ) $Val = [string]$Val + ":Ok" Write-Host $Val # $Val # exit 0 }
# exit 0
Value | Description |
---|---|
0 | all is well. The sensor in dashborde is colored green. The last message is highlighted in green.![]() |
one | Attention. The sensor is painted yellow. The last message is tinted yellowish![]() |
2 | System error. The sensor is painted red. The last message is highlighted in red. The message is logged to the alert.![]() |
3 | Protocol error (for example, web server returns 404). The sensor is painted red. The last message is red. Alert is highlighted. Protocol Error string added![]() |
four | The sensor is painted red. The last message is red. Alert is registered. Before the message appears Content Error![]() |
<prtg> <result> <channel> </channel> <value>100</value> </result> <result> <channel> </channel> <value>200</value> </result> </prtg>
"<prtg>" "<result>" "<channel>Total all accounts</channel>" "<value>$TotalAllAccountsBeg</value>" "<CustomUnit>RUB</CustomUnit>" "</result>" "<result>" "<channel>Total all accounts income</channel>" "<value>$TotalAllAccountsIncome</value>" "<CustomUnit>RUB</CustomUnit>" "</result>" "<result>" "<channel>Total all account outcome</channel>" "<value>$TotalAllAccountsOutcome</value>" "<CustomUnit>RUB</CustomUnit>" "</result>" "</prtg>"
{ "prtg": { "result": [ { "channel": " ", "value": "100" }, { "channel": " ", "value": "20" } ] } }
<Channel>Full list of tags here .
required
The channel name displayed in the user interface must be unique for each sensor in one sensor. There must not be 2 identical channel names.
value: any string
<Value>
required
integer or fractional value. If the PRTG cannot recognize it, it will display 0. Therefore, just check the output format, whether you output it correctly
value: integer or fractional
<CustomUnit>
not
if selected, this line is displayed below the numbers
for example RUB
value: any string, better short
<Unit>
not obligatory
If you want a built-in unit of measurement, you need to specify one of the built-in units. PRTG can understand time and scale some values (bytes - megabytes)
value:
BytesBandwidth
Bytes memory
Bytesdisk
Temperature
Percent
Timeresponse
Timeseconds
Custom
Count
CPU (*)
Bytesfile
Speeddisk
Speednet
Timehours
: 10 000 000,06 : 8 000 000,93 : 0 : 0 : 8 000 000,93 : 2 000 000,4 : 0 : 0 : 2 000 000,4 : 30 000,04 : 20 000,11 : 0 : 50 000,15
$FileName = 'C:\PRTG\data.txt' # $ErrorActionPreference = 'SilentlyContinue' # .. 1- # , function Get-Data{ Param( [parameter(Mandatory=$true)] [String] $SourceString ) $str = '' $str = $SourceString.Split(':') $str = $str[1] $str = $str.split(',') $str = $str[0] $str = $str -replace '\s','' return $str } if ((Test-Path $FileName) -eq $false) { exit 3 } $File = Get-Content $FileName | Select-String ":" $SalesToday = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccVTBBeg = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccVTBincome = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccVTBoutcome = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccVTBCurr = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccGosBeg = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccGosincome = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccGosoutcome = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccGosCurr = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccKassaBeg = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccKassaincome = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccKassaoutcome = Get-Data $File $File = Get-Content $FileName | Select-String " :" $AccKassaCurr = Get-Data $File $TotalAllAccountsBeg = [int]$AccVTBBeg + [int]$AccGosBeg + [int]$AccKassaBeg $TotalAllAccountsIncome = [int]$AccVTBincome + [int]$AccGosincome + [int]$AccKassaincome $TotalAllAccountsOutcome = [int]$AccVTBoutcome + [int]$AccGosoutcome + [int]$AccKassaoutcome $TotalAllAccountsCurr = [int]$AccVTBCurr + [int]$AccGosCurr + [int]$AccKassaCurr "<prtg>" "<result>" "<channel>Total all accounts</channel>" "<value>$TotalAllAccountsBeg</value>" "<CustomUnit>RUB</CustomUnit>" "</result>" "<result>" "<channel>Total all accounts income</channel>" "<value>$TotalAllAccountsIncome</value>" "<CustomUnit>RUB</CustomUnit>" "</result>" "<result>" "<channel>Total all account outcome</channel>" "<value>$TotalAllAccountsOutcome</value>" "<CustomUnit>RUB</CustomUnit>" "</result>" "<result>" "<channel>Total all account current</channel>" "<value>$TotalAllAccountsCurr</value>" "<CustomUnit>RUB</CustomUnit>" "</result>" "</prtg>"
Source: https://habr.com/ru/post/348088/
All Articles