No Problem but a Solution:

I had the problem, that i does not know how many sms Credits i had remaining at bulksms provider. So i write a PowerShell Script, and keep it simple, it works for me and maybe someone else can use this too.

Installation:

Copy the Script and save it as bulkSMSCreditStatus.ps1 Script see below. Put the Script into your PRTG Installation

e.g. C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML>

Add a new Sensor to the Server Probe, this make sense because, this Probe sends the sms messages.

Choose the Script Parameters new Sensor

Add Parameters: -bulksmsUSR YOUR_BULKSMSUER -bulksmsPW YOUR_Secret_Password

Important: Security Context ==> Use Windows credentials of parent device

Save and your finished.

Now you can define Values for LimitMinWarning and LimitMinError.

If everything is fine and works you should see this

Everythink OK

Please contact if questions occur.

#Get BulkSMS Credit Status
# v. 1.1
# © 2018 Frank Fischer
# www.freaky-media.de
#
#
################# 
# Settings for the Sensor
# Define Parameter with User and Password 
# -bulksmsUSR username_at_bulksms -bulksmsPW YourSuperSecretPW
#
# Security Context ==> Use Windows credentials of parent device
#
# Define Values for LimitMinWarning and LimitMinError
# v1.0 Initial Release
# v1.1 Change API URL 2018.06
#################


param(
$bulksmsUSR,
$bulksmsPW
)

#URL
[string]$bulksmsAPIURLCredits = "https://bulksms.vsms.net/eapi/user/get_credits/2/2.0?username=$bulksmsUSR&password=$bulksmsPW"

$WebResponse = Invoke-WebRequest $bulksmsAPIURLCredits

$bulksmsCredits = $WebResponse.ToString()
$bulksmsCredits = $bulksmsCredits.split("|")

$bulksmsStatus = $bulksmsCredits[0]
$bulksmsCreds = $bulksmsCredits[1]
if($bulksmsStatus -eq "0") 
{
Write-Host @"
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
   <result>
      <channel>API Status</channel>
      <value>$bulksmsStatus</value>
      <float>1</float>
      </result>
      <result>
      <channel>Credit Status</channel>
      <value>$bulksmsCreds</value>
      <customunit>Credits</customunit>
      <LimitMinWarning>50</LimitMinWarning>
      <LimitMinError>20</LimitMinError>
       <text>Remaining Credits</text>
      <float>1</float>       
   </result>
   

</prtg>
"@
}
else
{
Write-Host @"
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
   <error>1</error>
   <text>An Error occured: $bulksmsCreds</text>
   </prtg>
"@
}

Article Comments

Hi Frank,

Thanks for sharing! We'll review it and add it to our script world :)


Kind regards,
Stephan Linke, Tech Support Team


Jan, 2018 - Permalink

I have issue with this. Got this error, and ill copied the text into a ps1 file.

XML: Structural error in xml file, 1 open items. -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

Suggestions?


Mar, 2018 - Permalink

Hi, what happens when running script from Console? Is xml structure correct?


Mar, 2018 - Permalink

Also make sure that PRTG is able to execute PowerShell commands. Seems like the execution policy is not set correctly, hence the error. And what fischer said :)


Kind regards,
Stephan Linke, Tech Support Team


Mar, 2018 - Permalink

Cant Edit my First Post so i do a new Reply.

#Get BulkSMS Credit Status
# v. 1.1
# © 2018 Frank Fischer
# www.freaky-media.de
#
#
################# 
# Settings for the Sensor
# Define Parameter with User and Password 
# -bulksmsUSR username_at_bulksms -bulksmsPW YourSuperSecretPW
#
# Security Context ==> Use Windows credentials of parent device
#
# Define Values for LimitMinWarning and LimitMinError
# v1.0 Initial Release
# v1.1 Change API URL 2018.06
#################


param(
$bulksmsUSR,
$bulksmsPW
)

#URL
[string]$bulksmsAPIURLCredits = "https://bulksms.vsms.net/eapi/user/get_credits/2/2.0?username=$bulksmsUSR&password=$bulksmsPW"

$WebResponse = Invoke-WebRequest $bulksmsAPIURLCredits

$bulksmsCredits = $WebResponse.ToString()
$bulksmsCredits = $bulksmsCredits.split("|")

$bulksmsStatus = $bulksmsCredits[0]
$bulksmsCreds = $bulksmsCredits[1]
if($bulksmsStatus -eq "0") 
{
Write-Host @"
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
   <result>
      <channel>API Status</channel>
      <value>$bulksmsStatus</value>
      <float>1</float>
      </result>
      <result>
      <channel>Credit Status</channel>
      <value>$bulksmsCreds</value>
      <customunit>Credits</customunit>
      <LimitMinWarning>50</LimitMinWarning>
      <LimitMinError>20</LimitMinError>
       <text>Remaining Credits</text>
      <float>1</float>       
   </result>
   

</prtg>
"@
}
else
{
Write-Host @"
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
   <error>1</error>
   <text>An Error occured: $bulksmsCreds</text>
   </prtg>
"@
}

Jun, 2018 - Permalink

Hi Frank,

I modified the first reply accordingly. Thanks for your efforts! :)


Kind regards,
Stephan Linke, Tech Support Team


Jun, 2018 - Permalink

I have now set the execution policy to remote signed. Defined the parameters, have windows credentials under device. And the error i get now is

XML: Junk after document element </html> -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

And when i run the ps1 in powershell ice i get:

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\bulkSMSCreditStatus.ps1
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
<error>1</error>
<text>An Error occured: missing credentials (username was: )</text>
</prtg>

So what to do?


Sep, 2018 - Permalink

Hello Peter,

Please check if you run the script using the proper security context and also check if the sensor is set to use the Windows credentials from the device configuration as security context. Please also control whether the device configuration contains proper credentials.

Best regards,
Sebastian


Sep, 2018 - Permalink

What ill could see everything is correct. https://imgur.com/ndrIQft


Sep, 2018 - Permalink

Hello Peter,

Thank you very much for your reply.

Please note that we officially don't support custom scripts and my knowledge on this is quite limited to be honest. Please further debug the script and I'll ping Stephan to have a look at this, however due to his vacation the response will take a couple of days.

Thank you very much for your understanding.
Sebastian


Sep, 2018 - Permalink

Hello Peter,
i´m the creator of this script.

To run this in console you need the following Syntaxs.

bulkSMSCreditStatus.ps1 -bulksmsUSR yourUserName -bulksmsPW yourSecretPassword


Tell me what you get.


Sep, 2018 - Permalink

Hi Frank,

I appreciate your input.


Sep, 2018 - Permalink

The output ill get is:

Invoke-WebRequest : HTTP ERROR 404
Problem accessing /eapi/user/get_credits/2/2.0. Reason:
    unspecified
Powered by Jetty://
At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\bulkSMSCreditStatus.ps1:28 char:16
+ $WebResponse = Invoke-WebRequest $bulksmsAPIURLCredits
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
You cannot call a method on a null-valued expression.
At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\bulkSMSCreditStatus.ps1:30 char:1
+ $bulksmsCredits = $WebResponse.ToString()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\bulkSMSCreditStatus.ps1:31 char:1
+ $bulksmsCredits = $bulksmsCredits.split("|")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Cannot index into a null array.
At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\bulkSMSCreditStatus.ps1:33 char:1
+ $bulksmsStatus = $bulksmsCredits[0]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\bulkSMSCreditStatus.ps1:34 char:1
+ $bulksmsCreds = $bulksmsCredits[1]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Sep, 2018 - Permalink

Hi, think i found the Problem.

The Script is wrong. bulksms Changed some API so i edit the Code but after Change the Code, bulksms Changed Again.

!Can not Edit my First Post!

This here is the Code that worked (still in use in my Installation)

#Get BulkSMS Credit Status
# v. 1.2
# © 2018 Frank Fischer
# www.freaky-media.de
#
#
################# 
# Settings for the Sensor
# Define Parameter with User and Password 
# -bulksmsUSR username_at_bulksms -bulksmsPW YourSuperSecretPW
#
# Security Context ==> Use Windows credentials of parent device
#
# Define Values for LimitMinWarning and LimitMinError
# v1.0 Initial Release
# v1.1 Change API URL 2018.06
#################


param(
$bulksmsUSR,
$bulksmsPW
)

#URL
[string]$bulksmsAPIURLCredits = "https://bulksms.vsms.net/eapi/user/get_credits/1/1.1?username=$bulksmsUSR&password=$bulksmsPW"

$WebResponse = Invoke-WebRequest $bulksmsAPIURLCredits

$bulksmsCredits = $WebResponse.ToString()
$bulksmsCredits = $bulksmsCredits.split("|")

$bulksmsStatus = $bulksmsCredits[0]
$bulksmsCreds = $bulksmsCredits[1]
if($bulksmsStatus -eq "0") 
{
Write-Host @"
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
   <result>
      <channel>API Status</channel>
      <value>$bulksmsStatus</value>
      <float>1</float>
      </result>
      <result>
      <channel>Credit Status</channel>
      <value>$bulksmsCreds</value>
      <customunit>Credits</customunit>
      <LimitMinWarning>20</LimitMinWarning>
      <LimitMinError>10</LimitMinError>
       <text>Remaining Credits</text>
      <float>1</float>       
   </result>
   

</prtg>
"@
}
else
{
Write-Host @"
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
   <error>1</error>
   <text>An Error occured: $bulksmsCreds</text>
   </prtg>
"@
}
#END



Sep, 2018 - Permalink

Thank you,
now when ill run the script in powershell console, it reports fine.
But in PRTG i get "An Error occured" And this is from the sensor log.

Cannot index into a null array.
At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\bulkSMSCre
ditStatus.ps1:34 char:1
+ $bulksmsCreds = $bulksmsCredits[1]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray
 
<?xml version='1.0' encoding='UTF-8'?>
<prtg>
   <error>1</error>
   <text>An Error occured: </text>
   </prtg>

Sep, 2018 - Permalink

Hello Frank,

Any objections that I replace your original script with your latest one for you?

Best regards,
Sebastian


Sep, 2018 - Permalink

Hi all,

I've got encountered problems with "invoke-request" in PRTG. but i solved it and i share my experience.

my PRTG script only worked if I left a windows session open. as soon as I closed my session, PRTG went into errors ...

I've solved by addind "-UseBasicParsing" to the "invoke-webrequest" instruction :

$WebResponse = Invoke-WebRequest -UseBasicParsing -Uri $bulksmsAPIURLCredits

now i can deconnect from my windows session !


Mar, 2022 - Permalink