Advertisement
notrin

Untitled

Apr 14th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. <?php
  2. //date 4/14/2016
  3. //Smupper v3
  4. //author: Jeff Swenson js@mt.net j.swenson@simplixity.net
  5. ///user snmpget to retrieve ap information.
  6.  
  7. //set date variable
  8. $date = date("Y/m/d");
  9.  
  10. //connect to database via pdo
  11. $host = '127.0.0.1'; //host variable
  12. $db = 'adatabase';//database name variable
  13. $user = 'root';//database user variable
  14. $pass = "MontanaNet4**";//database user password variable
  15. $charset = 'utf8';//database charset type variable
  16.  
  17. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  18.  
  19. $opt = [
  20. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  21. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  22. PDO::ATTR_EMULATE_PREPARES => false,
  23. ];
  24.  
  25. $pdo = new PDO($dsn, $user, $pass, $opt);
  26.  
  27. //this is a counter
  28. $acount = '0';
  29.  
  30. //load sm list file:
  31. $array = array(); // this is the array for the data from siteList.txt will be stored.
  32. $handle = fopen("alist.txt", "r") or die("epic fail");
  33.  
  34. while(($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
  35. $array[$row[0]] = $row[0];
  36. }
  37. fclose($handle);
  38.  
  39. //display ammount of sites loaded in the array
  40. echo "there is ". count($array) . " sites loaded into the application" . "<br>";
  41.  
  42. sort($array);
  43. //loop through each item in the array
  44. foreach($array as $key => $ip){
  45. $community = "pass";
  46. //get the object ids
  47. $oid = ".1.3.6.1.2.1.1.5.0";
  48. $oid2 = ".1.3.6.1.4.1.161.19.3.1.7.1.0";
  49. $oidCC = ".1.3.6.1.4.1.161.19.3.1.10.1.1.6.1";
  50. //build the snmp2 get strings
  51. $test = snmp2_get($ip, $community, $oid);
  52. $test2 = snmp2_get($ip, $community, $oid2);
  53. $test3 = snmp2_get($ip, $community, $oidCC);
  54.  
  55. $acount++;
  56. if($test != FALSE){
  57. //echo $acount;
  58. $testa = substr($test, 5);
  59. $test2a = substr($test2, 3);
  60. $test3a = substr($test3, 3);
  61. //$test4a = substr($test4, 3);
  62. //print "ap name :" . $test . "sm count :" . $test2 . "<br>";
  63.  
  64. //trim the values in the array so they are human readable
  65. //print
  66. explode(' {',substr($test,strpos($test,': ') + 2))[0]
  67. . " count: " . substr($test2,strpos($test2,': ') + 2)
  68. //. " vlan: " . substr($test4,strpos($test4,': ') + 2)
  69. . " color code: " . substr($test3,strpos($test3,': ') + 2) ."<br>";
  70.  
  71. //insert into the database with pdo
  72. try {
  73. $stmt = $pdo->prepare("INSERT INTO nodeCounts(NodeID, Count, DateLogged) VALUES (:NodeID, :Count, :DateLogged)");
  74.  
  75. $stmt->bindParam(':NodeID', $test);
  76. $stmt->bindParam(':Count', $test2);
  77. $stmt->bindParam(':DateLogged', $date);
  78. echo "successful entry";
  79. } catch (PDOException $e) {
  80. echo "Error: " . $e->getMessage();
  81. }//end pdo insert to database.
  82. }
  83. $pdo = null;
  84. }
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement