Advertisement
Guest User

Untitled

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