asterisk_reload_conf.py 1.03 KB
Newer Older
1
#!/usr/bin/env python
2
# -*- mode: python; coding: utf-8 -*-
3
import asterisk
4 5 6 7
import time
import sys

timeout=10
8
server="asterisk.adm.crans.org"
9 10 11 12 13 14 15 16 17 18 19 20
port=5038

user="django"
password="HLWkzyITZAmBk"

reload_srv={
  'sip':['chan_sip'],
  'voicemail':['app_voicemail'],
  'dialplan':['pbx_config'],
  'all':['chan_sip','app_voicemail','pbx_config'],
}

21
manager = asterisk.Manager(user, password, server=server, auto_connect=False, timeout=timeout)
22 23
def reload_config(config):
    if not config in reload_srv.keys():
24
        print >> sys.stderr, "Usage %s [%s]" %(sys.argv[0],'|'.join(reload_srv.keys()))
25
        return
26
    manager.connect()
27
    for module in reload_srv[config]:
28
        try:manager.reload(module)
29
        except asterisk.AsteriskError: pass
30
    manager.logoff()
31 32 33 34 35 36 37 38

if __name__ == '__main__' :
    if len(sys.argv)<2:
        print >> sys.stderr, "Usage %s [%s]" %(sys.argv[0],'|'.join(reload_srv.keys()))
        print >> sys.stderr, "Reload config from : \n * %s" % ('\n * '.join(reload_srv.keys()))
        exit(1)
    reload_config(sys.argv[1])