Advertisement
Guest User

Untitled

a guest
May 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = 'root';//database user variable
  5. $password = "micadminpw1";//database user password variable
  6. $date = date("Y/m/d");
  7. //$date = "2016/08/08";
  8.  
  9. //connect to the database
  10. $conn = new PDO("mysql:host=$servername;dbname=thenetwork", $username, $password);
  11.  
  12. // set the PDO error mode to exception
  13. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  14. $nodesCounted =0; //a variable to use for counting nodes
  15. $failedCount =0; //a variable to use for counting nodes that do not respond snmp2
  16.  
  17.  
  18. //prepare the nodes to get counts from
  19. $sth = $conn->prepare("SELECT * FROM `nodenew` ORDER BY NodeName ASC");
  20.  
  21. $sth->bindParam(':ID', $ID);//node id
  22. $sth->bindParam(':NodeName', $NodeName);//node name
  23. $sth->bindParam(':NodeIP', $NodeIP);//node ip
  24. $sth->execute(); //get the database
  25.  
  26. //loop through each node, build snmp strings to get the count from each node;
  27. while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
  28.  
  29. //echo these values to see if the array is there
  30. if($row['NodeStatus'] == "1"){
  31. echo $row['ID'] . ' ' . $row['NodeName']. ' ' . $row['NodeIP'] . "<br>" ;
  32. $community = "micadmpasscomm";
  33.  
  34. //get the object ids
  35. $oid2 = ".1.3.6.1.4.1.161.19.3.1.7.1.0"; //sm count
  36. $oid3 = ".1.3.6.1.4.1.17713.21.1.2.10.0"; //epmp sm count
  37. $oid4 = ".1.3.6.1.4.1.41112.1.4.5.1.15";//ubnt sm count
  38.  
  39. //$oidCC = ".1.3.6.1.4.1.161.19.3.1.10.1.1.6.1"; //sm colorcode
  40.  
  41. //build the snmp2 get strings
  42. $test2 = snmp2_get($row['NodeIP'], $community, $oid2);
  43. echo $test2;
  44.  
  45. //if($test2 != 1){
  46. // $test2 = snmp2_get($row['NodeIP'], $community, $oid3);
  47. // }else if($test2 != 1){
  48. // $test2 = snmp2_get($row['NodeIP'], $community, $oid4);
  49. //} else {
  50. // $failedCount++;
  51. // }
  52.  
  53. //$test3 = snmp2_get($row['NodeIP'], $community, $oidCC);
  54. //echo $test2 ."<br>";
  55. //echo $test3 ."<br>";
  56.  
  57. //get the number count from the string variable
  58. //$aCount = 2;//
  59. $aCount = explode(' {',substr($test2,strpos($test2,': ') + 2))[0];
  60.  
  61. //a test to print the array
  62. echo $row['NodeName'] . "<br>" . $row['ID'] ." " .$aCount . "<br>";
  63.  
  64.  
  65. $ID = $row['ID']; //not sure i need to do this
  66.  
  67. //are these 2 lines considerd the same?
  68. $sql = "INSERT INTO `nodecounts`(`NodeID`,`aCount`,`DateLogged`) VALUES (:NodeID, :aCount, :DateLogged)";
  69.  
  70. $nodesCounted++;//a counter to tell how many sites have been counted
  71.  
  72. //prepare the db string to insert the counts into the nodecounts table
  73. $sth2 = $conn->prepare($sql);
  74. //bind parameters to variables
  75. $sth2->bindParam(':NodeID', $ID);
  76. $sth2->bindParam(':aCount', $aCount);
  77. $sth2->bindParam(':DateLogged', $date);
  78. $data = array(":NodeID" => $ID, ":aCount" => $aCount, ":DateLogged" => $date);
  79. print_r($data);//print the array for a test
  80.  
  81. //$stmt->execute();
  82. $sth2->execute();
  83. }
  84. else {
  85.  
  86. }
  87. }
  88. echo "there has been " . $nodesCounted . "sites sm counted";
  89. echo "there has been " . $failedCount . "sites failed";
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement