Advertisement
Guest User

Untitled

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