Channels.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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_CHANNELS_BRIDGED = '.1.3.6.1.4.1.22736.1.5.5.1.0';
  48. /**
  49. * Returns the current number of active channels.
  50. *
  51. * > Current number of active channels.
  52. *
  53. * @return int The current number of active channels.
  54. */
  55. public function active()
  56. {
  57. return $this->getSNMP()->get( self::OID_ASTERISK_CHANNELS_ACTIVE );
  58. }
  59. /**
  60. * Returns the number of channel types (technologies) supported.
  61. *
  62. * > Number of channel types (technologies) supported.
  63. *
  64. * @return int The number of channel types (technologies) supported.
  65. */
  66. public function supported()
  67. {
  68. return $this->getSNMP()->get( self::OID_ASTERISK_CHANNELS_SUPPORTED );
  69. }
  70. /**
  71. * Array of supported channel type names
  72. *
  73. * > Unique name of the technology we are describing.
  74. *
  75. * @return array Supported channel type names
  76. */
  77. public function names()
  78. {
  79. return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_NAME );
  80. }
  81. /**
  82. * Array of supported channel type descriptions
  83. *
  84. * > Description of the channel type (technology).
  85. *
  86. * @return array Supported channel type descriptions
  87. */
  88. public function descriptions()
  89. {
  90. return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_DESCRIPTION );
  91. }
  92. /**
  93. * Array of supported channel type device state capability
  94. *
  95. * > Whether the current technology can hold device states.
  96. *
  97. * @return array Whether the current technology can hold device states.
  98. */
  99. public function deviceStates()
  100. {
  101. return $this->getSNMP()->ppTruthValue( $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_STATE ) );
  102. }
  103. /**
  104. * Array of supported channel type progress indication capability
  105. *
  106. * > Whether the current technology supports progress indication.
  107. *
  108. * @return array Whether the current technology supports progress indication.
  109. */
  110. public function progressIndications()
  111. {
  112. return $this->getSNMP()->ppTruthValue( $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_INDICATION ) );
  113. }
  114. /**
  115. * Array of supported channel type transfer capability
  116. *
  117. * > Whether the current technology supports transfers, where
  118. * > Asterisk can get out from inbetween two bridged channels.
  119. *
  120. * @return array Whether the current technology transfers
  121. */
  122. public function transfers()
  123. {
  124. return $this->getSNMP()->ppTruthValue( $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_TRANSFER ) );
  125. }
  126. /**
  127. * Array of active calls on supported channels
  128. *
  129. * > Number of active channels using the current technology.
  130. *
  131. * @return array Active calls on supported channels
  132. */
  133. public function activeCalls()
  134. {
  135. return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_TYPE_CHANNELS );
  136. }
  137. /**
  138. * Number of channels currently in a bridged state.
  139. *
  140. * > Number of channels currently in a bridged state.
  141. *
  142. * @return int Array of active calls on supported channels
  143. */
  144. public function bridged()
  145. {
  146. return $this->getSNMP()->get( self::OID_ASTERISK_CHANNELS_BRIDGED );
  147. }
  148. /**
  149. * Utility function to gather channel details together in an associative array.
  150. *
  151. * Returns an array of support channel types. For example:
  152. *
  153. * Array
  154. * (
  155. * ....
  156. * [SIP] => Array
  157. * (
  158. * [name] => SIP
  159. * [index] => 5
  160. * [description] => Session Initiation Protocol (SIP)
  161. * [hasDeviceState] => 1
  162. * [hasProgressIndications] => 1
  163. * [canTransfer] => 1
  164. * [activeCalls] => 0
  165. * )
  166. * ....
  167. * )
  168. *
  169. * If you chose to index by SNMP table entries, the above element would be indexed with `5` rather than `SIP`.
  170. *
  171. * @param bool $useIndex If true, the array is indexed using the SNMP table index rather than the unique channel type name
  172. * @return array Channel details as an associative array
  173. */
  174. public function details( $useIndex = false )
  175. {
  176. $details = [];
  177. foreach( $this->names() as $index => $name )
  178. {
  179. if( $useIndex )
  180. $idx = $index;
  181. else
  182. $idx = $name;
  183. $details[ $idx ]['name'] = $name;
  184. $details[ $idx ]['index'] = $index;
  185. $details[ $idx ]['description'] = $this->descriptions()[$index];
  186. $details[ $idx ]['hasDeviceState'] = $this->deviceStates()[$index];
  187. $details[ $idx ]['hasProgressIndications'] = $this->progressIndications()[$index];
  188. $details[ $idx ]['canTransfer'] = $this->transfers()[$index];
  189. $details[ $idx ]['activeCalls'] = $this->activeCalls()[$index];
  190. }
  191. return $details;
  192. }
  193. }