7 # Copyleft 2005 by Chris Maj <cmaj_at_freedomcorpse_dot_com>
9 # Create a (huge) bunch of call files to dial via pbx_spool.
10 # Defaults are selected with 'Enter' and, if all defaults
11 # are selected, you'll dial Zap/1/s into default|s|1
15 # where Asterisk's pbx/pbx_spool.c will be looking for work
16 set SPOOLDIR
/var
/spool
/asterisk
/outgoing
17 # pbx_spool is fairly aggresive, so make files here first
20 if { ![file writable
$SPOOLDIR] } {
21 puts "Do you need to be root to write to $SPOOLDIR ?"
25 if { ![file readable
$TEMPDIR] } {
26 puts "Do you need to be root to read from $TEMPDIR ?"
30 if { ![file writable
$TEMPDIR] } {
31 puts "Do you need to be root to write to $TEMPDIR ?"
35 # gets some input from the user
36 proc get
{var_ default_ prompt_
} {
39 if { $default_ != "" } {
40 puts -nonewline "(default: $default_) ? "
46 if { [set $var_] == "" && $default_ != "" } {
51 # puts the user requested channels into a neat, ordered list
52 proc splitchans
{inch_
} {
55 foreach range
[split $inch_ {, }] {
56 set start
[lindex [split $range -] 0]
57 set stop
[lindex [split $range -] end
]
58 if { [string is digit
$start] && [string is digit
$stop] } {
59 set ::changroup "channel"
60 for {set ch
$start} {$ch <= $stop} {incr ch
} {
61 if { [lsearch $outch $ch] == -1 } {
66 set ::changroup "group"
67 foreach ch
[split $range -] {
72 return [lsort -dictionary $outch]
75 # writes out a file in the temporary directory,
76 # then changes the mtime of the file before
77 # sticking it into the outgoing spool directory
78 # (where pbx_spool will be looking)
79 proc spool
{channel_ callcnt_ when_
} {
81 Channel: $::technology/$channel_/$::destination
83 Extension: $::extension
86 RetryTime: $::retrytime
87 MaxRetries: $::maxretries
92 set fn
"loadtest.call$callcnt_.ch$channel_"
93 set fd
[open $::TEMPDIR/$fn w
]
96 file mtime
$::TEMPDIR/$fn $when_
97 file rename -force $::TEMPDIR/$fn $::SPOOLDIR/$fn
100 # prompt the user for some info
101 get technology
"Zap" "\nEnter technology type
103 get chans
"1" "\nEnter channel(s) or group to test in formats like
104 2\n1-4\n3 5 7 9\n1-23,25-47,49-71,73-95\ng4\ng2,g1"
105 set channels
[splitchans
$chans]
107 get destination
"s" "\nEnter destination number"
108 get context
"default" "\nEnter context"
109 get extension
"s" "\nEnter extension"
110 get priority
"1" "\nEnter priority"
111 get timeout
"45" "\nEnter timeout for call to be answered in seconds"
112 get maxretries
"0" "\nEnter maximum number of retries"
114 if { $maxretries > 0 } {
115 get retrytime
"300" "\nEnter time between retries in seconds"
120 get clid
"" "\nEnter callerid"
121 get astvar
"" "\nEnter some extra variables"
122 get account
"loadtest" "\nEnter account code"
123 get calls
"1" "\nEnter number of test calls per $changroup"
124 get period
"60" "\nEnter period between placing calls on a particular $changroup in seconds"
126 if { [llength $channels] > 1 } {
127 get rate
"0" "\nEnter period between placing each call in seconds
128 0 will send a call on each $changroup every $period seconds
129 1 will send a call on $changroup [lindex $channels 0] at [expr {$period + 0}]s, [lindex $channels 1] at [expr {$period + 1 }]s, etc.
130 5 will send a call on $changroup [lindex $channels 0] at [expr {$period + 0}]s, [lindex $channels 1] at [expr {$period + 5 }]s, etc."
135 puts -nonewline "\nCreating spooled call files... "
136 set now
[clock seconds
]
138 set spinner
[list / - \\ |
]
139 for {set i
0} {$i < $calls} {incr i
} {
140 foreach ch
$channels {
141 set chidx
[lsearch $channels $ch]
142 spool
$ch [incr spoolcnt
] [expr {$now + ($i * $period) + ($rate * $chidx)}]
144 puts -nonewline [lindex $spinner [expr {$spoolcnt % 4}]]
148 puts "\b$spoolcnt calls placed into $SPOOLDIR !"