役割の追加

最終更新日: 10 年 2023 月 XNUMX 日

LogicMonitor REST API v3 を使用して、LogicMonitor アカウントに新しいロールを追加できます。 API リクエストを行う前に、自分自身を認証する必要があります。

URI: 投稿 /setting/roles

タイプ説明
privilegesJSON配列(必須の) ロールに関連付けられたアカウント権限。 このオブジェクトには、ユーザーに付与された権限ごとにネストされたオブジェクトが含まれている必要があります。
アカウントの各領域のロールに権限を追加できます。 これには次のものが含まれます。
  • operation – 特権操作。 例 - "operation": "write"
  • objectId – 特権オブジェクトの識別子。 例 - "objectId": "123"
  • objectType – 特権オブジェクトのタイプ。 値は次のとおりです。 
    [dashboard_group|dashboard|host_group|service_group|website_group|report_group|remoteSession|chat|setting|device_dashboard|help|logs|configNeedDeviceManagePermission|map|resourceMapTab|tracesManageTab]

    例– "objectType": "dashboard group"
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スクリプトは、次の権限を持つロール「DBチーム」を追加します。

  • プライベートダッシュボードを管理する
  • ABC Corporation ダッシュボード グループを管理する
  • 「リソース割り当て」ダッシュボードを管理する
  • すべてのデバイス グループを表示する
  • デバイスのダッシュボードを管理する
  • 個人のユーザー プロファイル情報を編集する
  • APIトークンの管理
  • チャットを表示する

このロールにはさらに、ヘルプ メニューの下に表示されるカスタム ヘルプ URL とラベルが含まれています。

#!/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 ='POST'
resourcePath = '/setting/roles'
queryParams = ''
data = '{"name":"DB Team","customHelpLabel":"Internal Support Resources","customHelpURL":"https://logicmonitor.com/support","privileges":[{"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":"write"},{"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.post(url, data=data, headers=headers)
 
#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Pythonの3