Ad Widget

Collapse

dashboard.create

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RichardvD
    Junior Member
    • Aug 2023
    • 14

    #1

    dashboard.create

    Hi All,

    Anyone expirience with the API dashboard.create? I'm trying to device a script to bring Zabbix 5 dashboards to Zabbix6.
    When I run my script I get the following error and I have tried to fill the users array on several methods.

    pyzabbix.api.ZabbixAPIException: {'code': -32602, 'message': 'Invalid params.', 'data': 'Invalid parameter "/1/users/1": an array is expected.', 'json': "{'jsonrpc': '2.0', 'method': 'dashboard.create', 'params': {'name': 'Control-M', 'pages': {'height': '3', 'name': '', 'type': 'hostavail', 'view_mode': '0', 'widgetid': '146', 'width': '6', 'x': '12', 'y': '0\\n'}, 'users': {'userid': '115', 'permission': '2\\n'}, 'userGroups': {'usrgrpid': '19', 'permission': '2\\n'}}, 'id': '1', 'auth': '********'}"}

    Snippet of my (Python) script:

    # Get the user(s) for the dashboard
    def fill_user(dashid):
    ufile=open('dashboard-users.txt','r')
    for user in ufile:
    uf=user.split(";")
    # ua=[" "," "]
    # if uf[0] == dashid:
    # ua[0]=uf[1]
    # ua[1]=uf[2]
    # if ua[0] == ' ':
    # ua[0]=1
    # ua[1]=3
    ua={
    "userid": uf[1],
    "permission": uf[2]
    }
    #pprint(ua)
    ufile.close()
    return ua

    # Get the usergroup(s) for the dashboard
    def fill_usergroup(dashid):
    gfile=open('dashboard-usergroups.txt','r')
    for grp in gfile:
    g=grp.split(";")
    # ga=[" "," "]
    # if g[0] == dashid:
    # ga[0]=g[1]
    # ga[1]=g[2]
    # if ga[0] == ' ':
    # ga[0]=1
    # ga[1]=3
    ga={
    "usrgrpid": g[1],
    "permission": g[2]
    }
    #pprint(ga)
    gfile.close()
    return ga

    # Make the new dashboard
    def make_dashboard():
    dashid=line[0]
    name=line[1]
    #userid=get_user(line[2])
    userarr=fill_user(dashid)
    usgarr=fill_usergroup(dashid)
    pages=fill_pages(dashid)
    did=zapi.dashboard.create(name=name,pages=pages,us ers=userarr,userGroups=usgarr)
  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #2
    The users hould be an array of objects:
    PHP Code:
    ...
    'users': [{'userid''115''permission''2'}] 

    Comment


    • RichardvD
      RichardvD commented
      Editing a comment
      I modified the code to this:

      ua=[" "," "]
      if uf[0] == dashid:
      ua[0]=["userid: ",uf[1]]
      ua[1]=["permission: ",uf[2]]
      if ua[0] == ' ':
      ua[0]=["userid: 1"]
      ua[1]=["permission: 3"]

      But still no luck:

      pyzabbix.api.ZabbixAPIException: {'code': -32602, 'message': 'Invalid params.', 'data': 'Invalid parameter "/1/users/1": unexpected parameter "0".', 'json': "{'jsonrpc': '2.0', 'method': 'dashboard.create', 'params': {'name': 'Control-M', 'pages': {'height': '3', 'name': '', 'type': 'hostavail', 'view_mode': '0', 'widgetid': '146', 'width': '6', 'x': '12', 'y': '0\\n'}, 'users': [['userid: 1'], ['permission: 3']], 'userGroups': {'usrgrpid': '19', 'permission': '2\\n'}}, 'id': '1', 'auth': '********'}"}
  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #3
    As you can see in the error message, the users is now sent as array of arrays, while it needs to be array of objects. Instead of
    Code:
    'users': [['userid: 1'], ['permission: 3']]
    you need
    Code:
    'users': [{'userid: 1', 'permission: 3'}]
    Last edited by dimir; 25-09-2023, 17:07.

    Comment

    • Ranjith.Rokkam
      Junior Member
      • Oct 2023
      • 14

      #4
      Hi All,

      Can we get the customized dashboard templates to customer presentable.

      Comment

      Working...