def _connect_to_asterisk(self, cr, uid, context=None):
        '''
        Open the connection to the asterisk manager
        Returns an instance of the Asterisk Manager

        '''
        user = self.pool.get('res.users').browse(cr, uid, uid, context=context)

        # Note : if I write 'Error' without ' :', it won't get translated...
        # I don't understand why !

        ast_server = self._get_asterisk_server_from_user(cr, uid, user, context=context)
        # We check if the current user has a chan type
        if not user.asterisk_chan_type:
            raise osv.except_osv(_('Error :'), _('No channel type configured for the current user.'))

        # We check if the current user has an internal number
        if not user.resource:
            raise osv.except_osv(_('Error :'), _('No resource name configured for the current user'))


        _logger.debug("User's phone : %s/%s" % (user.asterisk_chan_type, user.resource))
        _logger.debug("Asterisk server = %s:%d" % (ast_server.ip_address, ast_server.port))

        # Connect to the Asterisk Manager Interface
        try:
            ast_manager = Manager.Manager((ast_server.ip_address, ast_server.port), ast_server.login, ast_server.password)
        except Exception, e:
            _logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address)
            _logger.error("Here is the detail of the error : '%s'" % unicode(e))
            raise osv.except_osv(_('Error :'), _("Problem in the request from OpenERP to Asterisk. Here is the detail of the error: '%s'" % unicode(e)))
            return False
    def test_ami_connection(self, cr, uid, ids, context=None):
        '''
        Test Ami Connection
        :param cr:
        :param uid:
        :param ids:
        :param context:
        :return:
        '''

        ast_server = self.browse(cr, uid, ids[0], context=context)
        ast_manager = False

        try:
            ast_manager = Manager.Manager(
                (ast_server.ip_address, ast_server.port),
                ast_server.login,
                ast_server.password)
        except Exception as e:
            raise orm.except_orm(
                _("Connection Test Failed!"),
                _("Here is the error message: %s" % e))
        finally:
            if ast_manager:
                ast_manager.Logoff()
        # Show Modal
        return {
            'name': _('Successful connection to Asterisk'),
            'type': 'ir.actions.act_window',
            'res_model': 'asterisk.success.connection.popup',
            'view_mode': 'form',
            'view_type': 'form',
            'target': 'new'
        }
示例#3
0
 def test_ami_connection(self):
     self.ensure_one()
     ast_manager = False
     try:
         ast_manager = Manager.Manager((self.ip_address, self.port),
                                       self.login, self.password)
     except Exception, e:
         raise UserError(
             _("Connection Test Failed! The error message is: %s" % e))
示例#4
0
 def test_ami_connection(self, cr, uid, ids, context=None):
     assert len(ids) == 1, 'Only 1 ID'
     ast_server = self.browse(cr, uid, ids[0], context=context)
     try:
         ast_manager = Manager.Manager(
             (ast_server.ip_address, ast_server.port), ast_server.login,
             ast_server.password)
     except Exception, e:
         raise orm.except_orm(_("Connection Test Failed!"),
                              _("Here is the error message: %s" % e))
示例#5
0
 def test_ami_connection(self):
     self.ensure_one()
     ast_manager = False
     try:
         ast_manager = Manager.Manager((self.ip_address, self.port),
                                       self.login, self.password)
     except Exception as e:
         raise UserError(
             _("Connection Test Failed! The error message is: %s" % e))
     finally:
         if ast_manager:
             ast_manager.Logoff()
     raise UserError(
         _("Connection Test Successfull! Odoo can successfully login to "
           "the Asterisk Manager Interface."))
    def _connect_to_asterisk(self, cr, uid, context=None):
        '''
        Open the connection to the Asterisk Manager
        Returns an instance of the Asterisk Manager
        '''
        user = self.pool['res.users'].browse(cr, uid, uid, context=context)

        ast_server = self._get_asterisk_server_from_user(
            cr, uid, context=context)

        # We check if the current user has a chan type
        if not user.asterisk_chan_type:
            raise orm.except_orm(
                _('Error:'),
                _('No channel type configured for the current user.'))

        # We check if the current user has an internal number
        if not user.resource:
            raise orm.except_orm(
                _('Error:'),
                _('No resource name configured for the current user'))

        _logger.debug(
            "User's phone: %s/%s" % (user.asterisk_chan_type, user.resource))
        _logger.debug(
            "Asterisk server: %s:%d"
            % (ast_server.ip_address, ast_server.port))

        # Connect to the Asterisk Manager Interface
        try:
            ast_manager = Manager.Manager(
                (ast_server.ip_address, ast_server.port),
                ast_server.login, ast_server.password)
        except Exception as e:
            _logger.error(
                "Error in the request to the Asterisk Manager Interface %s"
                % ast_server.ip_address)
            _logger.error("Here is the error message: %s" % e)
            raise orm.except_orm(
                _('Error:'),
                _("Problem in the request from OpenERP to Asterisk. "
                  "Here is the error message: %s" % e))

        return (user, ast_server, ast_manager)
示例#7
0
def command_line(argv):
    '''
    Act as a command-line tool.
    '''
    commands = ('actions', 'action', 'command', 'usage', 'help')

    if len(argv) < 2:
        raise ArgumentsError('please specify at least one argument.')

    command = argv[1]

    if command not in commands:
        raise ArgumentsError('invalid arguments.')

    if command == 'usage':
        return usage(argv[0], sys.stdout)

    manager = Manager.Manager(*Config.Config().get_connection())

    if command == 'actions':
        show_actions()

    if command == 'help':
        if len(argv) < 3:
            raise ArgumentsError('please specify an action.')

        show_actions(argv[2])

    elif command == 'action':
        if len(argv) < 3:
            raise ArgumentsError('please specify an action.')

        try:
            execute_action(manager, argv[2:])
        except TypeError:
            print "Bad arguments specified. Help for %s:" % (argv[2], )
            show_actions(argv[2])

    elif command == 'command':
        execute_action('command', argv[2])
示例#8
0
    def _connect_to_asterisk(self):
        '''
        Open the connection to the Asterisk Manager
        Returns an instance of the Asterisk Manager

        '''
        user = self.env.user
        ast_server = user.get_asterisk_server_from_user()
        # We check if the current user has a chan type
        if not user.asterisk_chan_type:
            raise UserError(
                _('No channel type configured for the current user.'))

        # We check if the current user has an internal number
        if not user.resource:
            raise UserError(
                _('No resource name configured for the current user'))

        _logger.debug("User's phone: %s/%s", user.asterisk_chan_type,
                      user.resource)
        _logger.debug("Asterisk server: %s:%d", ast_server.ip_address,
                      ast_server.port)

        # Connect to the Asterisk Manager Interface
        try:
            ast_manager = Manager.Manager(
                (ast_server.ip_address, ast_server.port), ast_server.login,
                ast_server.password)
        except Exception as e:
            _logger.error(
                "Error in the request to the Asterisk Manager Interface %s",
                ast_server.ip_address)
            _logger.error("Here is the error message: %s", e)
            raise UserError(
                _("Problem in the request from Odoo to Asterisk. "
                  "Here is the error message: %s" % e))

        return (user, ast_server, ast_manager)
if __name__ == '__main__':
    usage = "usage: %prog [options] email1 email2 email3 ..."
    epilog = "Script written by Alexis de Lattre. Published under the GNU GPL licence."
    description = "This script sends an e-mail when a SIP trunk is not registered."
    parser = OptionParser(usage=usage, epilog=epilog, description=description)
    for option in options:
        param = option['names']
        del option['names']
        parser.add_option(*param, **option)
    options, arguments = parser.parse_args()
    sys.argv[:] = arguments

    try:
        # Connect to AMI
        m = Manager.Manager((options.ip, options.port), options.login,
                            options.passwd)
        res = m.SipShowRegistry()
        if not options.silent:
            print "Sip show REGISTRY =", pformat(res)
    except Exception, e:
        subject = 'Cannot connect to the Asterisk Manager'
        body = u"""The monitoring script can't connect to the Asterisk Manager.\n\nHere are the details of the error :\n%s""" % e
        send_mail(subject, body)
        raise

    if not res:
        subject = "No SIP trunk"
        body = u"""The command "sip show registry" doesn't show any SIP trunk !\n\nHere are the details :\n%s""" % pformat(
            res)
        send_mail(subject, body)
示例#10
0
 def check_status(self):
     try:
         manager = Manager.Manager((self.host, self.port), self.login,
                                   self.password)
     except Exception, e:
         self.status = "Connection Test Failed! %s" % e
示例#11
0
 def connect_ami(self):
     try:
         manager = Manager((self.host, self.port), self.user, self.password)
         return manager
     except:
         return None