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

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Can i set access rights for the sensors and devices via API?

Votes:

0

Your Vote:

Up

Down

I need to restrict access to several thousands sensors in the diferent places of device tree for particular group.

access-rights api sensor

Created on Nov 2, 2018 2:34:24 PM by  Vitaliy Abuzov (0) 1



6 Replies

Accepted Answer

Votes:

2

Your Vote:

Up

Down

Hi Vitaliy,

This can be done fairly easily with PrtgAPI using PowerShell

While modifying access rights are not currently supported by PrtgAPI's type system, we can still modify the necessary properties for this by constructing a set of raw parameters

The following example shows how to grant Full access permissions to the user with ID 201 on all devices whose name starts with "exch"

Get-Device exch* | Set-ObjectProperty -RawParameters @{
    accessrights_=1
    accessrights_201=400
    accessgroup=0
} -Force

For ease of use, you can wrap this up in a simple cmdlet wherein you specify the devices, user ID and access level required for the user.

The following access levels can be specified

  • Inherited (-1)
  • None (0)
  • Read (100)
  • Write (200)
  • Full (400)
function Set-PrtgUserAccess
{
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline=$true)]
        $Device,

        [Parameter(Position=0)]
        $UserId,

        [Parameter(Position=1)]
        $Access
    )

    Process {
        $Device | Set-ObjectProperty -RawParameters @{
            accessrights_=1
            "accessrights_$UserId"=$Access
            accessgroup=0
        } -Force
    }
}
Get-Device exch* | Set-PrtgUserAccess 201 400

For more information on retrieving devices, please see the wiki

Regards,

lordmilko

Created on Nov 5, 2018 7:35:34 AM by  lordmilko (2,142) 2 1



Votes:

0

Your Vote:

Up

Down

Now where's that "Make Moderator" button again... :) Great work, thanks!


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team

Created on Nov 5, 2018 7:56:37 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi lordmilko! Thanks for yor answer! It is realy helps me alot.

Created on Nov 5, 2018 1:19:45 PM by  Vitaliy Abuzov (0) 1



Votes:

0

Your Vote:

Up

Down

Ok, I can set the access-rights. But only once. When I want to add rights for another user as well, then the rights for the first user are lost. Does that mean that when I update rights, I should set ALL rights <> -1 ? And I have a hard time finding why it's needed to add 'accessgroup=0'. What does it do?

Created on Nov 2, 2020 4:59:27 PM by  gjhiddink (0) 1



Votes:

2

Your Vote:

Up

Down

Hi gjhiddink,

You are correct - it appears sections like Access Rights require all of properties defined under them to be re-specified whenever you modify a setting. The PRTG UI always resubmits all settings whenever you save the page, however things would not be so simple for a third party library like PrtgAPI, hence why sections like this are currently unsupported.

You can still achieve this however by implementing your own solution that utilizes Get-ObjectProperty and Set-ObjectProperty to respecify all of the access rights properties whenever you apply a new one.

The following demonstrates how you could do this

function Set-PrtgUserAccess
{
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline=$true)]
        $Device,

        [Parameter(Position=0)]
        $UserId,

        [Parameter(Position=1)]
        $Access
    )

    Process {

        $properties = @(($Device | Get-ObjectProperty -Raw).PSObject.Properties|where name -like "accessrights_*")

        $candidateName = "accessrights_$UserId"

        if(!($properties|where Name -eq $candidateName))
        {
            throw "$UserId is not a valid UserId for this object. Valid values are $($properties.name -replace 'accessrights_','' -join ', ')"
        }

        $parameters = @{
            accessrights_=1
            accessgroup=0
        }

        foreach($property in $properties)
        {
            if($property.Name -eq $candidateName)
            {
                $parameters.$candidateName = $Access
            }
            else
            {
                $parameters.$($property.Name) = $property.Value
            }
        }

        $Device | Set-ObjectProperty -RawParameters $parameters -Force
    }
}
# Modify the access rights
Get-Device exch* | Set-PrtgUserAccess 301 100
Get-Device exch* | Set-PrtgUserAccess 302 100

# Confirm they were both changed correctly
Get-Device exch* | Get-ObjectProperty -Raw | select accessrights_*

In regards to the accessgroup=0 parameter, this corresponds to the "Inherit Access Rights" button found on the Settings page. Specifying a value of 0 indicates that you want inheritance of this section to be disabled, so that you can specify your own values.

Regards,

lordmilko

Created on Nov 3, 2020 7:04:58 AM by  lordmilko (2,142) 2 1



Votes:

0

Your Vote:

Up

Down

Thanks, @lordmilko! :)

Created on Nov 3, 2020 8:04:41 AM by  Stephan Linke [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.