Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = 'root';//database user variable
- $password = "MontanaNet4**";//database user password variable
- $date = date("Y/m/d");
- //connect to the database
- $conn = new PDO("mysql:host=$servername;dbname=adatabase", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $nodesCounted =0; //a variable to use for counting nodes
- //prepare the nodes to get counts from
- $sth = $conn->prepare("SELECT * FROM `node` ORDER BY NodeName ASC");
- $sth->bindParam(':ID', $ID);//node id
- $sth->bindParam(':NodeName', $NodeName);//node name
- $sth->bindParam(':NodeIP', $NodeIP);//node ip
- $sth->execute(); //get the database
- //loop through each node, build snmp strings to get the count from each node;
- while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
- //echo these values to see if the array is there
- // echo $row['ID'] . ' ' . $row['NodeName']. ' ' . $row['NodeIP'] . "<br>" ;
- $community = "micadmpasscomm";
- //get the object ids
- $oid2 = ".1.3.6.1.4.1.161.19.3.1.7.1.0"; //sm count
- $oidCC = ".1.3.6.1.4.1.161.19.3.1.10.1.1.6.1"; //sm colorcode
- //build the snmp2 get strings
- $test2 = snmp2_get($row['NodeIP'], $community, $oid2);
- //$test3 = snmp2_get($row['NodeIP'], $community, $oidCC);
- //echo $test2 ."<br>";
- //echo $test3 ."<br>";
- //get the number count from the string variable
- $aCount = explode(' {',substr($test2,strpos($test2,': ') + 2))[0];
- //a test to print the array
- //echo $row['NodeName'] . "<br>" . $row['ID'] ." " .$aCount . "<br>";'
- $ID = $row['ID'];//not sure i need to do this
- //are these 2 lines considerd the same?
- $sql = "INSERT INTO `nodecounts`(`ID`,`aCount`,`date`) VALUES (:NodeID, :aCount, :DateLogged)";
- $nodesCounted++;//a counter to tell how many sites have been counted
- //prepare the db string to insert the counts into the nodecounts table
- $sth = $conn->prepare($sql);
- //bind parameters to variables
- $sth->bindParam(':NodeID', $ID);
- $sth->bindParam(':aCount', $aCount);
- $sth->bindParam(':DateLogged', $date);
- $data = array(":ID" => $ID, ":aCount" => $aCount, ":DateLogged" => $date);
- print_r($data);//print the array for a test
- //$stmt->execute();
- $sth->execute($data);
- }
- echo "there has been " . $nodesCounted . "sites sm counted";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement