Ad Widget

Collapse

Get media assigned to users via API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zabbix-user007
    Junior Member
    • Jan 2025
    • 25

    #1

    Get media assigned to users via API

    Hello.

    i am trying to use teh API to get all users on an old 7.4 system, including the media and values assigned to user.
    for example the Email address assigned to the Media type = Email, or mobile number for SMS.

    I am using an API key assigned to a user who is a Zabbix Administrator and has theSuper Admin Role.

    however, i cannot see a method to do this.

    any assistance woudl be wlcome.

  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    user.get and selectMedia?
    selectMedias query Return media used by the user in the medias property.

    Comment

    • zabbix-user007
      Junior Member
      • Jan 2025
      • 25

      #3
      unfortunatrly, for some reason, that just returns, for instance "medias": [] against all users.

      Comment

      • LenR
        Senior Member
        • Sep 2009
        • 1005

        #4
        This is some code I wrote to get all medias. It uses pyzabbix. This code starts after a successful auth to the API. I'm adding comments after # in some lines, so cleanup will be needed. (pasting here messed up indentation also)

        medias = zapi.mediatype.get(output="extend") # Get all media types
        media_description = {} # Build a dict for the media descriptions

        for media in medias:
        media_description[media['mediatypeid']] = media['name']

        pprint.pprint(media_description) # Debugging

        active_message = {"0": "Active", "1": "Inactive"} # Pretty print active/inactive

        users = zapi.user.get(output="extend",selectMedias="extend ") # Get all users with their medias

        for user in users:
        for media in user["medias"]:
        if media_description[media["mediatypeid"]] != "Email": # I only wanted media's that weren't "Email"
        print(user["username"]+","+media_description[media["mediatypeid"]]+","+str(media["sendto"])+","+active_message[media["active"]])

        Comment

        • zabbix-user007
          Junior Member
          • Jan 2025
          • 25

          #5
          thanks, LenR.
          i will add this, especially getting the media descritpions part.
          I got it working with curl. not sure what i was doing wrong, actually, but i do need to add code to our repo and should switch to python, anyway for this.

          Comment

          Working...