mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	Use Log facility when Laravel is booted. Update init.php so we can easily boot Laravel for CLI scripts. (and just Eloquent, but that may go away) Move all debug setup into set_debug() function and use that across all scripts. Log Laravel database queries. Send debug output to librenms log file when enabling debug in the webui. Allow for colorized Log CLI output. (currently will leave % tags in log file output) ** Needs testing and perhaps tweaking still. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
		
			
				
	
	
		
			118 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			118 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
/* Copyright (C) 2014 Nicolas Armando <nicearma@yahoo.com> and Mathieu Millet <htam-net@github.net>
 | 
						|
* This program is free software: you can redistribute it and/or modify
 | 
						|
* it under the terms of the GNU General Public License as published by
 | 
						|
* the Free Software Foundation, either version 3 of the License, or
 | 
						|
* (at your option) any later version.
 | 
						|
*
 | 
						|
* This program is distributed in the hope that it will be useful,
 | 
						|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
 | 
						|
* GNU General Public License for more details.
 | 
						|
*
 | 
						|
* You should have received a copy of the GNU General Public License
 | 
						|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
 | 
						|
 | 
						|
 | 
						|
global $debug;
 | 
						|
 | 
						|
// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco
 | 
						|
use LibreNMS\Config;
 | 
						|
 | 
						|
if (Config::get('enable_vrf_lite_cisco')) {
 | 
						|
    $ids = array();
 | 
						|
 | 
						|
    // For the moment only will be cisco and the version 3
 | 
						|
    if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') {
 | 
						|
        $mib = "SNMP-COMMUNITY-MIB";
 | 
						|
        $mib = "CISCO-CONTEXT-MAPPING-MIB";
 | 
						|
        //-Osq because if i put the n the oid from the first command is not the same of this one
 | 
						|
        $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, null);
 | 
						|
        $listVrf = str_replace("cContextMappingVrfName.", "", $listVrf);
 | 
						|
        $listVrf = str_replace('"', "", $listVrf);
 | 
						|
        $listVrf = trim($listVrf);
 | 
						|
 | 
						|
        d_echo("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n");
 | 
						|
        d_echo("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n");
 | 
						|
 | 
						|
        foreach (explode("\n", $listVrf) as $lineVrf) {
 | 
						|
            $tmpVrf = explode(" ", $lineVrf, 2);
 | 
						|
            //the $tmpVrf[0] will be the context
 | 
						|
            if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) {
 | 
						|
                $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1];
 | 
						|
            }
 | 
						|
        }
 | 
						|
        unset($listVrf);
 | 
						|
 | 
						|
        $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, null);
 | 
						|
        $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance);
 | 
						|
        $listIntance = str_replace('"', "", $listIntance);
 | 
						|
        $listIntance = trim($listIntance);
 | 
						|
 | 
						|
        d_echo("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n");
 | 
						|
        d_echo("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n");
 | 
						|
 | 
						|
        foreach (explode("\n", $listIntance) as $lineIntance) {
 | 
						|
            $tmpIntance = explode(" ", $lineIntance, 2);
 | 
						|
            //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance
 | 
						|
            if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) {
 | 
						|
                $tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1];
 | 
						|
            }
 | 
						|
        }
 | 
						|
        unset($listIntance);
 | 
						|
 | 
						|
        foreach ((array)$tableVrf as $context => $vrf) {
 | 
						|
            if ($debug) {
 | 
						|
                echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n");
 | 
						|
            }
 | 
						|
 | 
						|
            $tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array(
 | 
						|
                $device ['device_id'],
 | 
						|
                $context
 | 
						|
            ));
 | 
						|
            if (!empty($tmpVrf)) {
 | 
						|
                $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id'];
 | 
						|
                $vrfUpdate=array();
 | 
						|
 | 
						|
                foreach ($vrfUpdate as $key => $value) {
 | 
						|
                    if ($vrf[$key]!=$value) {
 | 
						|
                        $vrfUpdate[$key]=$value;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                if (!empty($vrfUpdate)) {
 | 
						|
                    dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array(
 | 
						|
                        $tmp['vrf_lite_cisco_id']
 | 
						|
                    ));
 | 
						|
                }
 | 
						|
            } else {
 | 
						|
                $id = dbInsert(array(
 | 
						|
                    'device_id' => $device ['device_id'],
 | 
						|
                    'context_name' => $context,
 | 
						|
                    'intance_name' => $vrf['intance_name'],
 | 
						|
                    'vrf_name' => $vrf['vrf_name']
 | 
						|
                        ), 'vrf_lite_cisco');
 | 
						|
                $ids[$id] = $id;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        unset($tableVrf);
 | 
						|
    }
 | 
						|
 | 
						|
    //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work
 | 
						|
    $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array(
 | 
						|
        $device ['device_id']));
 | 
						|
    $device['vrf_lite_cisco'] = $tmpVrfC;
 | 
						|
 | 
						|
    //Delete all vrf that chaged
 | 
						|
    foreach ($tmpVrfC as $vrfC) {
 | 
						|
        unset($ids[$vrfC['vrf_lite_cisco_id']]);
 | 
						|
    }
 | 
						|
    if (!empty($ids)) {
 | 
						|
        foreach ($ids as $id) {
 | 
						|
            dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array($id));
 | 
						|
        }
 | 
						|
    }
 | 
						|
    unset($ids);
 | 
						|
    unset($tmpVrfC);
 | 
						|
} // enable_vrf_lite_cisco
 |