役割の詳細の更新
最終更新日: 10 年 2023 月 XNUMX 日LogicMonitor REST API v3 を使用してロールの詳細を更新できます。 API リクエストを行う前に、自分自身を認証する必要があります。
ロールを部分的に更新するには、 PATCH
リクエスト。 ロールを完全に更新するには、 PUT
リクエストで詳細に指定された通りになります。
URI: パッチ /setting/roles/{id}
URI: 置く /setting/roles/{id}
注: REST 標準に従って、PUT リクエストで指定されていないプロパティはデフォルト値に戻ります。
説明 | ||
id | 整数 | (必須の) 更新するロールの ID。 |
privileges | JSON配列 | (必須の) ロールに関連付けられたアカウント権限。 このオブジェクトには、ユーザーに付与された権限ごとにネストされたオブジェクトが含まれている必要があります。 アカウントの各領域のロールに権限を追加できます。 これには次のものが含まれます。
|
description | 文字列 | 役割の説明。 例 - "description": "Administrator can do everything, including security-sensitive actions." |
customHelpLabel | 文字列 | [ヘルプとサポート] ドロップダウン メニューに表示されるカスタム ヘルプ URL のラベル。 例 - "customHelpLabel": "Internal Support Resources" |
customHelpURL | 文字列 | [ヘルプとサポート] ドロップダウン メニューに追加する URL。 例 - "customHelpURL": "https://logicmonitor.com/support" |
name | 文字列 | (必須の) ロールの名前。 ロール名は、数字、文字、- および _ 記号に制限されます。 例 - "name": "administrator" |
twoFARequired | ブーリアン | このロールに 2 要素認証 (XNUMXFA) が必要かどうかを示します。 例 - "twoFARequired": true |
requireEULA | ブーリアン | このロールに関連付けられたユーザーがエンド ユーザー使用許諾契約 (EULA) に同意する必要があるかどうかを示します。 例 - "requireEULA": false |
roleGroupId | 整数 | 更新するロールのグループ ID。 例 - "roleGroupId": 2 |
次の Python スクリプトは、ID 28 のロールの権限を更新します。
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
#Request Info
httpVerb ='PUT'
resourcePath = '/setting/roles/28'
queryParams = ''
data = '{"name":"Server Team","customHelpLabel":"Internal Support Resources","customHelpURL":"https://logicmonitor.com/support","privileges":[{"objectType":"setting","objectId":"collectorgroup.4","objectName":"collectorgroup.4","operation":"write"},{"objectType":"setting","objectId":"collector.*","objectName":"collector.*","operation":"read"},{"objectType":"dashboard_group","objectId":"private","objectName":"private","operation":"write"},{"objectType":"dashboard_group","objectId":4,"objectName":"ABC Corporation","operation":"write"},{"objectType":"dashboard","objectId":77,"objectName":"Resource Allocation","operation":"write"},{"objectType":"host_group","objectId":"*","objectName":"*","operation":"read"},{"objectType":"deviceDashboard","objectId":"","operation":"read"},{"objectType":"setting","objectId":"useraccess.personalinfo","operation":"write"},{"objectType":"setting","objectId":"useraccess.apitoken","operation":"write"},{"objectType":"help","objectId":"chat","objectName":"help","operation":"write"}]}'
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath +queryParams
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature digest = hmac.new(
AccessKey.encode('utf-8'),
msg=requestVars.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':3}
#Make request
response = requests.put(url, data=data, headers=headers)
#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)