Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //date 4/14/2016
- //Smupper v3
- //author: Jeff Swenson js@mt.net j.swenson@simplixity.net
- ///user snmpget to retrieve ap information.
- //set date variable
- $date = date("Y/m/d");
- //connect to database via pdo
- $host = '127.0.0.1'; //host variable
- $db = 'adatabase';//database name variable
- $user = 'root';//database user variable
- $pass = "MontanaNet4**";//database user password variable
- $charset = 'utf8';//database charset type variable
- $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
- $opt = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $pdo = new PDO($dsn, $user, $pass, $opt);
- //this is a counter
- $acount = '0';
- //load sm list file:
- $array = array(); // this is the array for the data from siteList.txt will be stored.
- $handle = fopen("alist.txt", "r") or die("epic fail");
- while(($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
- $array[$row[0]] = $row[0];
- }
- fclose($handle);
- //display ammount of sites loaded in the array
- echo "there is ". count($array) . " sites loaded into the application" . "<br>";
- sort($array);
- //loop through each item in the array
- foreach($array as $key => $ip){
- $community = "pass";
- //get the object ids
- $oid = ".1.3.6.1.2.1.1.5.0";
- $oid2 = ".1.3.6.1.4.1.161.19.3.1.7.1.0";
- $oidCC = ".1.3.6.1.4.1.161.19.3.1.10.1.1.6.1";
- //build the snmp2 get strings
- $test = snmp2_get($ip, $community, $oid);
- $test2 = snmp2_get($ip, $community, $oid2);
- $test3 = snmp2_get($ip, $community, $oidCC);
- $acount++;
- if($test != FALSE){
- //echo $acount;
- $testa = substr($test, 5);
- $test2a = substr($test2, 3);
- $test3a = substr($test3, 3);
- //$test4a = substr($test4, 3);
- //print "ap name :" . $test . "sm count :" . $test2 . "<br>";
- //trim the values in the array so they are human readable
- //print
- explode(' {',substr($test,strpos($test,': ') + 2))[0]
- . " count: " . substr($test2,strpos($test2,': ') + 2)
- //. " vlan: " . substr($test4,strpos($test4,': ') + 2)
- . " color code: " . substr($test3,strpos($test3,': ') + 2) ."<br>";
- //insert into the database with pdo
- try {
- $stmt = $pdo->prepare("INSERT INTO nodeCounts(NodeID, Count, DateLogged) VALUES (:NodeID, :Count, :DateLogged)");
- $stmt->bindParam(':NodeID', $test);
- $stmt->bindParam(':Count', $test2);
- $stmt->bindParam(':DateLogged', $date);
- echo "successful entry";
- } catch (PDOException $e) {
- echo "Error: " . $e->getMessage();
- }//end pdo insert to database.
- }
- $pdo = null;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement