Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = 'root';//database user variable
- $password = "micadminpw1";//database user password variable
- $date = date("Y/m/d");
- //$date = "2016/08/08";
- //connect to the database
- $conn = new PDO("mysql:host=$servername;dbname=thenetwork", $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
- $failedCount =0; //a variable to use for counting nodes that do not respond snmp2
- //prepare the nodes to get counts from
- $sth = $conn->prepare("SELECT * FROM `nodenew` 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
- if($row['NodeStatus'] == "1"){
- 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
- $oid3 = ".1.3.6.1.4.1.17713.21.1.2.10.0"; //epmp sm count
- $oid4 = ".1.3.6.1.4.1.41112.1.4.5.1.15";//ubnt 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);
- echo $test2;
- //if($test2 != 1){
- // $test2 = snmp2_get($row['NodeIP'], $community, $oid3);
- // }else if($test2 != 1){
- // $test2 = snmp2_get($row['NodeIP'], $community, $oid4);
- //} else {
- // $failedCount++;
- // }
- //$test3 = snmp2_get($row['NodeIP'], $community, $oidCC);
- //echo $test2 ."<br>";
- //echo $test3 ."<br>";
- //get the number count from the string variable
- //$aCount = 2;//
- $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`(`NodeID`,`aCount`,`DateLogged`) 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
- $sth2 = $conn->prepare($sql);
- //bind parameters to variables
- $sth2->bindParam(':NodeID', $ID);
- $sth2->bindParam(':aCount', $aCount);
- $sth2->bindParam(':DateLogged', $date);
- $data = array(":NodeID" => $ID, ":aCount" => $aCount, ":DateLogged" => $date);
- print_r($data);//print the array for a test
- //$stmt->execute();
- $sth2->execute();
- }
- else {
- }
- }
- echo "there has been " . $nodesCounted . "sites sm counted";
- echo "there has been " . $failedCount . "sites failed";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement