GithubHelp home page GithubHelp logo

Comments (4)

towster avatar towster commented on August 12, 2024

So hacking at the code I managed to get first issue to work. The issue is within zabbixconn.py.

Line 115 in get_mediatype_id reads:
result = self.conn.mediatype.get(filter={'description': description})

I changed to:
result = self.conn.mediatype.get(filter={'name': description})

Before I did that I did try setting the description of the media types to match the names but it still always found the wrong one.

from zabbix-ldap-sync.

towster avatar towster commented on August 12, 2024

Ok so that this may help someone else gonna paste this here. It is messy but it works. The second issue is because when you update a user you have to pass ALL of the media types for that user or it will remove any that you are not passing. I changed the code to pull the current media types that dont match the one we are changing and append that to the update.

Here is what I changed in zabbixconn.py to fix the second issue:

    def update_media(self, user, description, sendto, media_opt):
        """
        Adds media to an existing Zabbix user

        Args:
            user        (dict): A dict containing the user details
            description  (str): A string containing Zabbix media description
            sendto       (str): A string containing address, phone number, etc...
            media_opt    (dict): Media options

        """

        userid = self.get_user_id(user)
        mediatypeid = self.get_mediatype_id(description)

        if mediatypeid:
            media_temp = {
                'mediatypeid': mediatypeid,
                'sendto': sendto,
                'active': '0',
                'severity': '63',
                'period': '1-7,00:00-24:00'
            }
            media_temp.update(media_opt)

            currmediatemp = self.conn.user.get(selectMedias=['mediatypeid','sendto','active','severity','period'],userids=userid,output='medias')
            self.logger.debug('update_media - currmediatemp %s' % (currmediatemp))

            currmedia = currmediatemp[0]['medias']
            self.logger.debug('update_media - currmedia %s' % (currmedia))
            media_defaults = [media_temp] 
            for m in currmedia:
                if m['mediatypeid'] != mediatypeid:
                   media_defaults.append(m)
            
            self.logger.debug('update_media - userid %s - mediatypeid %s - media_defaults %s' % (userid, mediatypeid, media_defaults))

            if self.conn.api_version() >= "3.4":
                result = self.conn.user.update(userid=str(userid), user_medias=media_defaults)
            else:
                self.delete_media_by_description(user, description)
                result = self.conn.user.updatemedia(users=[{"userid": str(userid)}], medias=media_defaults)
        else:
            result = None

        return result

from zabbix-ldap-sync.

scoopex avatar scoopex commented on August 12, 2024

Thank you.
Can you send your contribution as a pull request?

from zabbix-ldap-sync.

scoopex avatar scoopex commented on August 12, 2024

solved

from zabbix-ldap-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.