Channels.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /*
  3. Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  4. All rights reserved.
  5. Contact: Barry O'Donovan - barry (at) opensolutions (dot) ie
  6. http://www.opensolutions.ie/
  7. This file is part of the OSS_SNMP package.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. * Neither the name of Open Source Solutions Limited nor the
  16. names of its contributors may be used to endorse or promote products
  17. derived from this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  22. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. namespace OSS\SNMP\MIBS\Asterisk;
  30. /**
  31. * A class for performing SNMP V2 queries on Asterisk
  32. *
  33. * @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+MIB+Definitions
  34. * @copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  35. * @author Barry O'Donovan <barry@opensolutions.ie>
  36. */
  37. class Channels extends \OSS\SNMP\MIB
  38. {
  39. const OID_ASTERISK_CHANNELS_ACTIVE = '.1.3.6.1.4.1.22736.1.5.1.0';
  40. const OID_ASTERISK_CHANNELS_SUPPORTED = '.1.3.6.1.4.1.22736.1.5.3.0';
  41. const OID_ASTERISK_CHANNEL_TYPE_NAME = '.1.3.6.1.4.1.22736.1.5.4.1.2';
  42. const OID_ASTERISK_CHANNEL_TYPE_DESCRIPTION = '.1.3.6.1.4.1.22736.1.5.4.1.3';
  43. const OID_ASTERISK_CHANNEL_TYPE_STATE = '.1.3.6.1.4.1.22736.1.5.4.1.4';
  44. const OID_ASTERISK_CHANNEL_TYPE_INDICATION = '.1.3.6.1.4.1.22736.1.5.4.1.5';
  45. const OID_ASTERISK_CHANNEL_TYPE_TRANSFER = '.1.3.6.1.4.1.22736.1.5.4.1.6';
  46. const OID_ASTERISK_CHANNEL_TYPE_CHANNELS = '.1.3.6.1.4.1.22736.1.5.4.1.7';
  47. const OID_ASTERISK_CHANNEL_NAME = '.1.3.6.1.4.1.22736.1.5.2.1.2';
  48. const OID_ASTERISK_CHANNEL_LANGUAGE = '.1.3.6.1.4.1.22736.1.5.2.1.3';
  49. const OID_ASTERISK_CHANNEL_TYPE = '.1.3.6.1.4.1.22736.1.5.2.1.4';
  50. const OID_ASTERISK_CHANNEL_MUSIC_CLASS = '.1.3.6.1.4.1.22736.1.5.2.1.5';
  51. const OID_ASTERISK_CHANNEL_BRIDGE = '.1.3.6.1.4.1.22736.1.5.2.1.6';
  52. const OID_ASTERISK_CHANNEL_MASQ = '.1.3.6.1.4.1.22736.1.5.2.1.7';
  53. const OID_ASTERISK_CHANNEL_MASQR = '.1.3.6.1.4.1.22736.1.5.2.1.8';
  54. const OID_ASTERISK_CHANNEL_WHEN_HANGUP = '.1.3.6.1.4.1.22736.1.5.2.1.9';
  55. const OID_ASTERISK_CHANNEL_APP = '.1.3.6.1.4.1.22736.1.5.2.1.10';
  56. const OID_ASTERISK_CHANNEL_DATA = '.1.3.6.1.4.1.22736.1.5.2.1.11';
  57. const OID_ASTERISK_CHANNEL_CONTEXT = '.1.3.6.1.4.1.22736.1.5.2.1.12';
  58. const OID_ASTERISK_CHANNEL_MACRO_CONTEXT = '.1.3.6.1.4.1.22736.1.5.2.1.13';
  59. const OID_ASTERISK_CHANNEL_MACRO_EXTEN = '.1.3.6.1.4.1.22736.1.5.2.1.14';
  60. const OID_ASTERISK_CHANNEL_MACRO_PRI = '.1.3.6.1.4.1.22736.1.5.2.1.15';
  61. const OID_ASTERISK_CHANNEL_EXTEN = '.1.3.6.1.4.1.22736.1.5.2.1.16';
  62. const OID_ASTERISK_CHANNEL_PRI = '.1.3.6.1.4.1.22736.1.5.2.1.17';
  63. const OID_ASTERISK_CHANNEL_ACCOUNT_CODE = '.1.3.6.1.4.1.22736.1.5.2.1.18';
  64. const OID_ASTERISK_CHANNEL_FORWARD_TO = '.1.3.6.1.4.1.22736.1.5.2.1.19';
  65. const OID_ASTERISK_CHANNEL_UNQIUEID = '.1.3.6.1.4.1.22736.1.5.2.1.20';
  66. const OID_ASTERISK_CHANNEL_CALL_GROUP = '.1.3.6.1.4.1.22736.1.5.2.1.21';
  67. const OID_ASTERISK_CHANNEL_PICKUP_GROUP = '.1.3.6.1.4.1.22736.1.5.2.1.22';
  68. const OID_ASTERISK_CHANNEL_STATE = '.1.3.6.1.4.1.22736.1.5.2.1.23';
  69. const OID_ASTERISK_CHANNEL_MUTED = '.1.3.6.1.4.1.22736.1.5.2.1.24';
  70. const OID_ASTERISK_CHANNEL_RINGS = '.1.3.6.1.4.1.22736.1.5.2.1.25';
  71. const OID_ASTERISK_CHANNEL_CID_DNID = '.1.3.6.1.4.1.22736.1.5.2.1.26';
  72. const OID_ASTERISK_CHANNEL_CID_NUM = '.1.3.6.1.4.1.22736.1.5.2.1.27';
  73. const OID_ASTERISK_CHANNEL_CID_NAME = '.1.3.6.1.4.1.22736.1.5.2.1.28';
  74. const OID_ASTERISK_CHANNEL_CID_ANI = '.1.3.6.1.4.1.22736.1.5.2.1.29';
  75. const OID_ASTERISK_CHANNEL_CID_RDNIS = '.1.3.6.1.4.1.22736.1.5.2.1.30';
  76. const OID_ASTERISK_CHANNEL_CID_PRESENTATION = '.1.3.6.1.4.1.22736.1.5.2.1.31';
  77. const OID_ASTERISK_CHANNEL_CID_ANI2 = '.1.3.6.1.4.1.22736.1.5.2.1.32';
  78. const OID_ASTERISK_CHANNEL_CID_TON = '.1.3.6.1.4.1.22736.1.5.2.1.33';
  79. const OID_ASTERISK_CHANNEL_CID_TNS = '.1.3.6.1.4.1.22736.1.5.2.1.34';
  80. const OID_ASTERISK_CHANNEL_AMA_FLAGS = '.1.3.6.1.4.1.22736.1.5.2.1.35';
  81. const OID_ASTERISK_CHANNEL_ADSI = '.1.3.6.1.4.1.22736.1.5.2.1.36';
  82. const OID_ASTERISK_CHANNEL_TIME_ZONE = '.1.3.6.1.4.1.22736.1.5.2.1.37';
  83. const OID_ASTERISK_CHANNEL_HANGUP_CAUSE = '.1.3.6.1.4.1.22736.1.5.2.1.38';
  84. const OID_ASTERISK_CHANNEL_VARIABLES = '.1.3.6.1.4.1.22736.1.5.2.1.39';
  85. const OID_ASTERISK_CHANNEL_FLAGS = '.1.3.6.1.4.1.22736.1.5.2.1.40';
  86. const OID_ASTERISK_CHANNEL_TRANSFER_CAP = '.1.3.6.1.4.1.22736.1.5.2.1.41';
  87. const OID_ASTERISK_CHANNELS_BRIDGED = '.1.3.6.1.4.1.22736.1.5.5.1.0';
  88. /**
  89. * Returns the current number of active channels.
  90. *
  91. * > Current number of active channels.
  92. *
  93. * @return int The current number of active channels.
  94. */
  95. public function active()
  96. {
  97. return $this->getSNMP()->get( self::OID_ASTERISK_CHANNELS_ACTIVE );
  98. }
  99. /**
  100. * Returns the number of channel types (technologies) supported.
  101. *
  102. * > Number of channel types (technologies) supported.
  103. *
  104. * @return int The number of channel types (technologies) supported.
  105. */
  106. public function supported()
  107. {
  108. return $this->getSNMP()->get( self::OID_ASTERISK_CHANNELS_SUPPORTED );
  109. }
  110. /**
  111. * Array of supported channel type names
  112. *
  113. * > Unique name of the technology we are describing.
  114. *
  115. * @return array Supported channel type names
  116. */
  117. public function names()
  118. {
  119. return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_NAME );
  120. }
  121. /**
  122. * Array of supported channel type descriptions
  123. *
  124. * > Description of the channel type (technology).
  125. *
  126. * @return array Supported channel type descriptions
  127. */
  128. public function descriptions()
  129. {
  130. return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_DESCRIPTION );
  131. }
  132. /**
  133. * Array of supported channel type device state capability
  134. *
  135. * > Whether the current technology can hold device states.
  136. *
  137. * @return array Whether the current technology can hold device states.
  138. */
  139. public function deviceStates()
  140. {
  141. return $this->getSNMP()->ppTruthValue( $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_STATE ) );
  142. }
  143. /**
  144. * Array of supported channel type progress indication capability
  145. *
  146. * > Whether the current technology supports progress indication.
  147. *
  148. * @return array Whether the current technology supports progress indication.
  149. */
  150. public function progressIndications()
  151. {
  152. return $this->getSNMP()->ppTruthValue( $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_INDICATION ) );
  153. }
  154. /**
  155. * Array of supported channel type transfer capability
  156. *
  157. * > Whether the current technology supports transfers, where
  158. * > Asterisk can get out from inbetween two bridged channels.
  159. *
  160. * @return array Whether the current technology transfers
  161. */
  162. public function transfers()
  163. {
  164. return $this->getSNMP()->ppTruthValue( $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_TRANSFER ) );
  165. }
  166. /**
  167. * Array of active calls on supported channels
  168. *
  169. * > Number of active channels using the current technology.
  170. *
  171. * @return array Active calls on supported channels
  172. */
  173. public function activeCalls()
  174. {
  175. return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_CHANNELS );
  176. }
  177. /**
  178. * Number of channels currently in a bridged state.
  179. *
  180. * > Number of channels currently in a bridged state.
  181. *
  182. * @return int Array of active calls on supported channels
  183. */
  184. public function bridged()
  185. {
  186. return $this->getSNMP()->get( self::OID_ASTERISK_CHANNELS_BRIDGED );
  187. }
  188. /**
  189. * Utility function to gather channel details together in an associative array.
  190. *
  191. * Returns an array of support channel types. For example:
  192. *
  193. * Array
  194. * (
  195. * ....
  196. * [SIP] => Array
  197. * (
  198. * [name] => SIP
  199. * [index] => 5
  200. * [description] => Session Initiation Protocol (SIP)
  201. * [hasDeviceState] => 1
  202. * [hasProgressIndications] => 1
  203. * [canTransfer] => 1
  204. * [activeCalls] => 0
  205. * )
  206. * ....
  207. * )
  208. *
  209. * If you chose to index by SNMP table entries, the above element would be indexed with `5` rather than `SIP`.
  210. *
  211. * @param bool $useIndex If true, the array is indexed using the SNMP table index rather than the unique channel type name
  212. * @return array Channel details as an associative array
  213. */
  214. public function details( $useIndex = false )
  215. {
  216. $details = [];
  217. foreach( $this->names() as $index => $name )
  218. {
  219. if( $useIndex )
  220. $idx = $index;
  221. else
  222. $idx = $name;
  223. $details[ $idx ]['name'] = $name;
  224. $details[ $idx ]['index'] = $index;
  225. $details[ $idx ]['description'] = $this->descriptions()[$index];
  226. $details[ $idx ]['hasDeviceState'] = $this->deviceStates()[$index];
  227. $details[ $idx ]['hasProgressIndications'] = $this->progressIndications()[$index];
  228. $details[ $idx ]['canTransfer'] = $this->transfers()[$index];
  229. $details[ $idx ]['activeCalls'] = $this->activeCalls()[$index];
  230. }
  231. return $details;
  232. }
  233. }