Hi Paessler,
I'm working on monthly report that is required to know how many users are in a specific user group in prtg. Just wondering if there's a way to automate this via API without logging on and manually check on prtg - system administration?
Thanks and regards, Terry
Article Comments
Hi Stephan, Sorry I'm not able to check the link right now but I'm after number of users per group, for example, I have a user group call ReadOnly which only have read access to our PRTG and I want to check the number of users in that group every month.
Thanks and regards Terry
Jan, 2017 - Permalink
Hi Stephan,
Just tested the link, I could write up a script to count the users/group from that. Just wondering if we can have csv version of this, that would be great?
Jan, 2017 - Permalink
Yes, I just need to write a script to count the users, should be all good, thanks Stephan
Jan, 2017 - Permalink
Okay cool :) Feel free to post the working script here and I'll promote it as best answer; then other users can find it better and make use of your work as well :)
Jan, 2017 - Permalink
Hi Stephan,
I ran into another problem. I tried to download the report page via powershell but it would then redirected me to prtg login page. I tried both web-request method and create an ie object, but neither of them work. Is there a way I can get the report without manually logon and download it?
web-request method:
$R = Invoke-WebRequest $prtglink -SessionVariable test
$test
$Form = $R.Forms[0]
$Form | Format-List
$Form.fields
$Form.Fields["loginusername"] = "$username"
$Form.Fields["loginpassword"] = "$password"
$R = Invoke-WebRequest -Uri ("$prtglink" + $Form.Action) -WebSession $test -Method POST -Body $Form.Fields
$R.Content
#R.content showing login page
create an ie object:
$reportlink = "$prtglink/config_report_users.htm"
$ie = new-object -com "InternetExplorer.Application"
$ie.Visible = $true
$ie.Navigate("$reportlink")
While ($ie.Busy) {
Sleep 2
}
$doc = $ie.Document
#$doc return null
Jan, 2017 - Permalink
You could simply call the URL with username and passhash GET parameters and you won't have to deal with the actual login:
http://<your-prtg-url>/config_report_users.htm?username=prtgadmin&passhash=12345678
Jan, 2017 - Permalink
Okie cool, I thought that wasn't available. Thanks Stephan, will try it on Monday
Jan, 2017 - Permalink
Hi Stephan,
Thank you for your help. I'm able to get my script working now. Please see below for details:
$reportlink = $UserDetails.UserDetails.PRTG2+"/config_report_users.htm?username=$username&passhash=$passhash"
$report = Invoke-WebRequest $reportlink
$report = $report.Content
$groupID = "123456789" #group id
$grouptag = ($report -split "id=`"$groupID`"")[-1]
$grouptag = ($grouptag -split "</tr>")[0]
#"class=`"col-primarygroup`"" count primary users of the group
#"class=`"col-members`"" count members of the group
# in my case I only need primary users
$PrimeUsers = ($grouptag -split "class=`"col-primarygroup`"")[-1]
$PrimeUsers = $PrimeUsers.split(",")
$usersCount = $PrimeUsers.Length
Regards
Jan, 2017 - Permalink
Hm, not via API, the following URL contains a report on users and groups:
<your-prtg-url>/config_report_users.htmOr do you need a numerical evaluation of the user / group configuration?
Jan, 2017 - Permalink