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


bulkSMS get Remaining Credits

Votes:

0

Your Vote:

Up

Down

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>
"@
}

bulksms credits powerhsell prtg status

Created on Jan 10, 2018 12:23:07 PM by  Frank Fischer (10) 2

Last change on Jun 25, 2018 11:43:38 AM by  Stephan Linke [Paessler Support]



16 Replies

Votes:

0

Your Vote:

Up

Down

Hi Frank,

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


Kind regards,
Stephan Linke, Tech Support Team

Created on Jan 10, 2018 12:39:33 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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?

Created on Mar 16, 2018 12:45:37 PM by  PeterH (0) 1

Last change on Mar 16, 2018 1:29:37 PM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Mar 17, 2018 9:32:24 AM by  Frank Fischer (10) 2

Last change on Jun 25, 2018 11:37:03 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Mar 19, 2018 10:03:49 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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>
"@
}

Created on Jun 25, 2018 11:08:51 AM by  Frank Fischer (10) 2

Last change on Jun 25, 2018 11:43:25 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Frank,

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


Kind regards,
Stephan Linke, Tech Support Team

Created on Jun 25, 2018 11:44:11 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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?

Created on Sep 6, 2018 8:40:49 AM by  PeterH (0) 1

Last change on Sep 6, 2018 12:26:05 PM by  Sebastian Kniege [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Sep 6, 2018 12:28:47 PM by  Sebastian Kniege [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Sep 6, 2018 1:36:11 PM by  PeterH (0) 1



Votes:

0

Your Vote:

Up

Down

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

Created on Sep 7, 2018 7:31:19 AM by  Sebastian Kniege [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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.

Created on Sep 7, 2018 7:26:27 PM by  Frank Fischer (10) 2

Last change on Sep 10, 2018 7:50:21 AM by  Sebastian Kniege [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Frank,

I appreciate your input.

Created on Sep 10, 2018 7:50:49 AM by  Sebastian Kniege [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Sep 10, 2018 8:24:30 AM by  PeterH (0) 1

Last change on Sep 10, 2018 9:11:00 AM by  Sebastian Kniege [Paessler Support]



Votes:

1

Your Vote:

Up

Down

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


Created on Sep 10, 2018 2:35:35 PM by  Frank Fischer (10) 2



Votes:

0

Your Vote:

Up

Down

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>

Created on Sep 11, 2018 5:24:18 AM by  PeterH (0) 1

Last change on Sep 11, 2018 5:44:06 AM by  Sebastian Kniege [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello Frank,

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

Best regards,
Sebastian

Created on Sep 11, 2018 5:47:21 AM by  Sebastian Kniege [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.