Admin Roles
The admin/roles resource can be used to manage M/Monit roles.
Available methods:
GET | 
                /api/2/admin/roles/list | The roles list | 
POST | 
                /api/2/admin/roles/create | Create a new role | 
POST | 
                /api/2/admin/roles/update | Update a role | 
POST | 
                /api/2/admin/roles/delete | Delete a role | 
POST | 
                /api/2/admin/roles/adduser | Assign a role to the user | 
POST | 
                /api/2/admin/roles/removeuser | Revoke a role from the user | 
POST | 
                /api/2/admin/roles/updateactive | Activate or deactivate the role | 
list
Returns a list of all M/Monit roles.
Arguments
| none | 
curl -b ~/.mmonit/cookie \
 https://127.0.0.1:8080/api/2/admin/roles/list
Output
| id | The numeric role id (immutable) | 
| name | The role name | 
| description | The role description | 
| admin | True if it's an administrator role, false for normal role | 
| active | True of the role is active, false if disabled | 
| buildin | True if the role is buildin (protected from removal), false for custom, fully managed roles | 
| rolerows | |
| hosts | The numeric array of host ids, the role applies to | 
| hostgroups | The numeric array of host group ids, the role applies to | 
| permissions | The permissions for hosts and hostgroups | 
| members | |
| users | The user ids of role members | 
[
    {
        "id": 4,
        "name": "admin",
        "description": "The super administrator role",
        "admin": true,
        "active": true,
        "buildin": true,
        "rolerows": [{
            "hosts": [],
            "hostgroups": [],
            "permission": ["1", "2", "4"]
        }],
        "members": {
            "users": ["1"]
        }
    }
]
create
Create a new M/Monit role. Parameters with space in them must be URL encoded (space=%20) as curl won’t escape it automatically.
Arguments
| name | string | required | The role name | 
| admin | boolean | required | True, if the role will be the M/Monit administrator role, with full access to M/Monit application parts and data | 
| active | boolean | required | True, if the role is active, otherwise false (the role is disabled) | 
| description | string | optional | Rule description | 
| rolerowscount | number | optional | Number of role rows (the number N is used as a numeric index for hostsN, hostgroupsN, permissionN, useridN) | 
| hostsN | number | optional | Target host id | 
| hostgroupsN | number | optional | Target host group id | 
| permissionN | number | optional | The bitmap of permissions, granted to the user (0=None, 1=collector, 2=view, 4=serviceactions) | 
| useridN | number | optional | The userids assigned to this role | 
curl -b ~/.mmonit/cookie \
 -d name=test \
 -d description="test%20role" \
 -d admin=false \
 -d active=true \
 -d rolerowscount=1 \
 -d hosts1=12 \
 -d permission1=1 \
 -d userid=1 \
 https://127.0.0.1:8080/api/2/admin/roles/create
Output
| id | The role id | 
update
Update role in the M/Monit database. Parameters with space in them must be URL encoded (space=%20) as curl won’t escape it automatically.
Arguments
| id | number | required | The role id to update | 
| name | string | required | The role name | 
| admin | boolean | required | True, if the role will be the M/Monit administrator role, with full access to M/Monit application parts and data | 
| active | boolean | required | True, if the role is active, otherwise false (the role is disabled) | 
| description | string | optional | Rule description | 
| rolerowscount | number | optional | Number of role rows (the number N is used as a numeric index for hostsN, hostgroupsN, permissionN, useridN) | 
| hostsN | number | optional | Target host id | 
| hostgroupsN | number | optional | Target host group id | 
| permissionN | number | optional | The bitmap of permissions, granted to the user (0=None, 1=collector, 2=view, 4=serviceactions) | 
| useridN | number | optional | The userids assigned to this role | 
curl -b ~/.mmonit/cookie \
 -d id=123 \ 
 -d name=test \ 
 -d description="test%20role" \
 -d admin=false \       
 -d active=true \
 -d rolerowscount=1 \   
 -d hosts1=12 \         
 -d permission1=1 \
 -d userid=1 \  
 https://127.0.0.1:8080/api/2/admin/roles/update
delete
Deletes the role with the given id.
Arguments
| id | number | required | The role id to delete | 
curl -b ~/.mmonit/cookie \
 -d id=123 \
 https://127.0.0.1:8080/api/2/admin/roles/delete
adduser
Add users to the role
Arguments
| id | number | required | The role id to modify | 
| userid | number | required | The userid to assign to the role. You can use this attribute multiple times to assign multiple users at once | 
curl -b ~/.mmonit/cookie \
 -d id=123 \    
 -d userid=678 \    
 -d userid=679 \    
 https://127.0.0.1:8080/api/2/admin/roles/adduser
removeuser
Remove users from the role
Arguments
| id | number | required | The role id to modify | 
| userid | number | required | The userid to remove from the role. You can use this attribute multiple times to remove multiple users at once | 
curl -b ~/.mmonit/cookie \
 -d id=123 \   
 -d userid=678 \   
 -d userid=679 \   
 https://127.0.0.1:8080/api/2/admin/roles/removeuser
updateactive
Activate or deactivate the role
Arguments
| id | number | required | The role id to modify | 
| active | boolean | required | True to activate the role, false to deactive it | 
curl -b ~/.mmonit/cookie \
 -d id=123 \
 -d active=false \
 https://127.0.0.1:8080/api/2/admin/roles/updateactive