System.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 generic devices
  32. *
  33. * @copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  34. * @author Barry O'Donovan <barry@opensolutions.ie>
  35. */
  36. class System extends \OSS\SNMP\MIB
  37. {
  38. const OID_SYSTEM_DESCRIPTION = '.1.3.6.1.2.1.1.1.0';
  39. const OID_SYSTEM_UPTIME = '.1.3.6.1.2.1.1.3.0';
  40. const OID_SYSTEM_CONTACT = '.1.3.6.1.2.1.1.4.0';
  41. const OID_SYSTEM_NAME = '.1.3.6.1.2.1.1.5.0';
  42. const OID_SYSTEM_LOCATION = '.1.3.6.1.2.1.1.6.0';
  43. const OID_SYSTEM_SERVICES = '.1.3.6.1.2.1.1.7.0';
  44. /**
  45. * Returns the system description of the device
  46. *
  47. * @return string The system description of the device
  48. */
  49. public function description()
  50. {
  51. return $this->getSNMP()->get( self::OID_SYSTEM_DESCRIPTION );
  52. }
  53. /**
  54. * Returns the system uptime of the device
  55. *
  56. * "The time (in hundredths of a second) since the
  57. * network management portion of the system was last
  58. * re-initialized."
  59. *
  60. * @return int The system uptime of the device (in timeticks)
  61. */
  62. public function uptime()
  63. {
  64. return $this->getSNMP()->get( self::OID_SYSTEM_UPTIME );
  65. }
  66. /**
  67. * Returns the system contact of the device
  68. *
  69. * @return string The system contact of the device
  70. */
  71. public function contact()
  72. {
  73. return $this->getSNMP()->get( self::OID_SYSTEM_CONTACT );
  74. }
  75. /**
  76. * Returns the system name of the device
  77. *
  78. * @return string The system name of the device
  79. */
  80. public function name()
  81. {
  82. return $this->getSNMP()->get( self::OID_SYSTEM_NAME );
  83. }
  84. /**
  85. * Returns the system location of the device
  86. *
  87. * @return string The system location of the device
  88. */
  89. public function location()
  90. {
  91. return $this->getSNMP()->get( self::OID_SYSTEM_LOCATION );
  92. }
  93. /**
  94. * Returns the system services of the device
  95. *
  96. * "A value which indicates the set of services that
  97. * this entity primarily offers.
  98. *
  99. * The value is a sum. This sum initially takes the
  100. * value zero, Then, for each layer, L, in the range
  101. * 1 through 7, that this node performs transactions
  102. * for, 2 raised to (L - 1) is added to the sum. For
  103. * example, a node which performs primarily routing
  104. * functions would have a value of 4 (2^(3-1)). In
  105. * contrast, a node which is a host offering
  106. * application services would have a value of 72
  107. * (2^(4-1) + 2^(7-1)). Note that in the context of
  108. * the Internet suite of protocols, values should be
  109. * calculated accordingly:
  110. *
  111. * layer functionality
  112. * 1 physical (e.g., repeaters)
  113. * 2 datalink/subnetwork (e.g., bridges)
  114. * 3 internet (e.g., IP gateways)
  115. * 4 end-to-end (e.g., IP hosts)
  116. * 7 applications (e.g., mail relays)
  117. *
  118. * For systems including OSI protocols, layers 5 and
  119. * 6 may also be counted."
  120. *
  121. * @return string The system services of the device
  122. */
  123. public function services()
  124. {
  125. return $this->getSNMP()->get( self::OID_SYSTEM_SERVICES );
  126. }
  127. /**
  128. * Gets all system values as an associate array
  129. *
  130. * The keys of the array are contact, description, location,
  131. * name, services, uptime
  132. *
  133. * @return array All system values as an associate array
  134. */
  135. public function getAll()
  136. {
  137. $system = array();
  138. $system[ 'contact' ] = $this->contact();
  139. $system[ 'description' ] = $this->description();
  140. $system[ 'location' ] = $this->location();
  141. $system[ 'name' ] = $this->name();
  142. $system[ 'services' ] = $this->services();
  143. $system[ 'uptime' ] = $this->uptime();
  144. return $system;
  145. }
  146. }