-
Notifications
You must be signed in to change notification settings - Fork 37
/
asterisk-recover
executable file
·70 lines (45 loc) · 1.78 KB
/
asterisk-recover
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python2.3
'''
Recover a channel lost in asterisk. Usage:
asterisk-recover <lost_channel> <context> <exten> <priority>
'''
__author__ = 'David Wilson'
__id__ = '$Id: asterisk-dump 3 2004-09-03 01:41:42Z dw $'
import sys
from Asterisk.Config import Config
from Asterisk.Manager import Manager
def main(argv):
manager = Manager(*Config().get_connection())
statii = manager.Status()
if not len(statii):
print >> sys.stderr, 'No channels active.'
print
raise SystemExit, 0
if len(sys.argv) == 5:
manager.Redirect(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
else:
chans = [ x for x in statii.items() if not x[1].has_key('Extension') ]
for nr, (channel, status) in enumerate(chans):
print 'Channel #%d:' % (nr+1, ), channel
if len(status['CallerID']):
print ' Caller ID:', status['CallerID']
if status.has_key('Link') and len(status['Link']):
print ' Link:', status['Link']
print
try:
chan_nr = input('Channel number [default: 1]: ') - 1
except SyntaxError, e:
print 'Using channel #1.'
chan_nr = 1
if len(chans) < chan_nr:
print 'Using channel #1.'
chan_nr = 0
else:
chan_nr -= 1
context = raw_input('Context [default: local_extensions]: ') or 'local_extensions'
exten = raw_input('Extension [default: 101]: ') or '101'
priority = raw_input('Priority [default: 1]: ') or '1'
print 'Redirecting', chans[chan_nr][0], 'to', '%s:%s@%s' % (exten, priority, context)
manager.Redirect(chans[chan_nr][0], context, exten, priority)
if __name__ == '__main__':
main(sys.argv[1:])