Asterisk.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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;
  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 Asterisk extends \OSS\SNMP\MIB
  38. {
  39. const OID_ASTERISK_VERSION_STRING = '.1.3.6.1.4.1.22736.1.1.1.0';
  40. const OID_ASTERISK_VERSION_TAG = '.1.3.6.1.4.1.22736.1.1.2.0';
  41. const OID_ASTERISK_UP_TIME = '.1.3.6.1.4.1.22736.1.2.1.0';
  42. const OID_ASTERISK_RELOAD_TIME = '.1.3.6.1.4.1.22736.1.2.2.0';
  43. const OID_ASTERISK_PID = '.1.3.6.1.4.1.22736.1.2.3.0';
  44. const OID_ASTERISK_CONTROL_SOCKET = '.1.3.6.1.4.1.22736.1.2.4.0';
  45. const OID_ASTERISK_CALLS_ACTIVE = '.1.3.6.1.4.1.22736.1.2.5.0';
  46. const OID_ASTERISK_CALLS_PROCESSED = '.1.3.6.1.4.1.22736.1.2.6.0';
  47. const OID_ASTERISK_MODULES = '.1.3.6.1.4.1.22736.1.3.1.0';
  48. /**
  49. * Returns the version of Asterisk
  50. *
  51. * > Text version string of the version of Asterisk that
  52. * > the SNMP Agent was compiled to run against.
  53. *
  54. * @return string The version of Asterisk
  55. */
  56. public function version()
  57. {
  58. return $this->getSNMP()->get( self::OID_ASTERISK_VERSION_STRING );
  59. }
  60. /**
  61. * Returns the Subversion (SVN) revision of Asterisk
  62. *
  63. * > SubVersion revision of the version of Asterisk that
  64. * > the SNMP Agent was compiled to run against -- this is
  65. * > typically 0 for release-versions of Asterisk.
  66. *
  67. * @return int The SVN revision of Asterisk
  68. */
  69. public function tag()
  70. {
  71. return $this->getSNMP()->get( self::OID_ASTERISK_VERSION_TAG );
  72. }
  73. /**
  74. * Returns the time ticks (100th sec) since Asterisk was started
  75. *
  76. * > Time ticks since Asterisk was started.
  77. *
  78. * @return int Time ticks since Asterisk was started
  79. */
  80. public function uptime()
  81. {
  82. return $this->getSNMP()->get( self::OID_ASTERISK_UP_TIME );
  83. }
  84. /**
  85. * Returns the time ticks (100th sec) since the Asterisk config was reload
  86. *
  87. * > Time ticks since Asterisk was last reloaded.
  88. *
  89. * @return int Time ticks since the Asterisk config was reload
  90. */
  91. public function reloadTime()
  92. {
  93. return $this->getSNMP()->get( self::OID_ASTERISK_RELOAD_TIME );
  94. }
  95. /**
  96. * Returns the process ID of the Asterisk instance
  97. *
  98. * > The process id of the running Asterisk process.
  99. *
  100. * @return int The process ID of the Asterisk instance
  101. */
  102. public function pid()
  103. {
  104. return $this->getSNMP()->get( self::OID_ASTERISK_PID );
  105. }
  106. /**
  107. * Returns the path for the control socket for giving Asterisk commands
  108. *
  109. * > The control socket for giving Asterisk commands.
  110. *
  111. * @return string The control socket for giving Asterisk commands
  112. */
  113. public function controlSocket()
  114. {
  115. return $this->getSNMP()->get( self::OID_ASTERISK_CONTROL_SOCKET );
  116. }
  117. /**
  118. * Returns the number of calls currently active on the Asterisk PBX.
  119. *
  120. * > The number of calls currently active on the Asterisk PBX.
  121. *
  122. * @return int The number of calls currently active on the Asterisk PBX.
  123. */
  124. public function callsActive()
  125. {
  126. return $this->getSNMP()->get( self::OID_ASTERISK_CALLS_ACTIVE );
  127. }
  128. /**
  129. * Returns the total number of calls processed through the Asterisk PBX since last restart.
  130. *
  131. * > The total number of calls processed through the Asterisk PBX since last restart.
  132. *
  133. * @return int The total number of calls processed through the Asterisk PBX since last restart.
  134. */
  135. public function callsProcessed()
  136. {
  137. return $this->getSNMP()->get( self::OID_ASTERISK_CALLS_PROCESSED );
  138. }
  139. /**
  140. * Returns the number of modules currently loaded into Asterisk.
  141. *
  142. * > Number of modules currently loaded into Asterisk.
  143. *
  144. * @return int The number of modules currently loaded into Asterisk
  145. */
  146. public function modules()
  147. {
  148. return $this->getSNMP()->get( self::OID_ASTERISK_MODULES );
  149. }
  150. }