#! /usr/bin/env perl

# just a simple script for people more familiar with
# perl syntax than YAML. Modify %config below, then run
# this script. It will create the configuration file for
# you.
use strict;
use warnings;

use YAML::Tiny; # apt-get libyaml-tiny-perl under debian
use File::Spec; # find location of script so we can put storage in same directory
use File::Basename;


my %config = (
      # one or more switches and their corresponding
      # community name. Use v1 snmp only
      'switches' => {
         'DNS or IP' => { # enter a DNS name or an IP address to be scanned.
            'community' => 'snmp community name',
            # the following list can be used to ignore ports on this switch. Note that these are the port numbers
            # returned by OID iso.3.6.1.2.1.2.2.1.8
            'portsToIgnore' => ['port','numbers','to','ignore']
         },
         'DNS or IP' => {
            'community' => 'snmp community name',
            'portsToIgnore' => ['port','numbers','to','ignore']
         }
      },
      # You must include at least one router.
      # this will be queried to resolve IP's to MAC 
      # using its arp table
      # put IP and community name into the hash
      'routers' =>  {
            'DNS or IP' => {
               'community' => 'snmp community name',
            },
            'DNS or IP' => {
               'community' => 'snmp community name',
            }
      },
      # this is entire optional, but if it exists, it will be used to supplement or override MAC to IP to DNS lookup.
      # Each entry is optional
      # MAC is the hexidecimal mac address, with no delimiters and all lower case. Example is: 
      #    402cf4e9ae9b      CORRECT
      #    40:2c:f4:e9:ae:9b WRONG, has delimiters (the colons)
      #    402CF4E9AE9B      WRONG, alphas are upper case
      # ip:       if this is entered, will be used as IP for the mac address, otherwise it is looked up in the routers arp table.
      #           default is to get IP from router's arp table
      # hostname: If this is entered, will be used for hostname, otherwise done via reverse DNS entry from router. Default is
      #           to look up via rdns
      # override: If false, ip/hostname only be used if no value returned from arp/rdns. If true, ip/hostname are not even
      #           attempted, ie this will override anything in those services. Default is false, only use if you can not find
      #           it.
      'staticmaps' => {
         'MAC1' => {
            'ip' => '1.1.1.1',
            'hostname' => 'some.host.name',
            'override' => 0
            },
         'MAC2' => {
            'ip' => '1.1.1.2',
            'hostname' => 'some other host name',
            'override' => 1
         }
      },
      # Optional files to be processed for items which were not in the router
      # these are assumed to be tab delimited files which contain the column
      # headers 'hostname', 'mac' and 'ip', with values below
      # this can be done via staticmaps (above), but is set up as an alternative
      # here for very large files, say from database dumps
      # files are assumed to be in the script directory
      'nonrouter' => (
         'filename1',
         'filename2'
      ),
      # instead of doing all of the snmp walks, if refresh is set, it will only check the
      # switch ports to see if they have changed MAC addresses. Once every 'refresh' time
      # a full rescan of port names, switch names, and rdns look ups will occur
      # using this cuts the time to run by about 1/3      
      'refresh' => 'seconds',
      # If set, entries which have not been seen for this period of time
      # are removed. Modifiers are h, d, w, m, y (hours, days, weeks, months, years)
      'ttl' => 'seconds'
      
          
      
   );

my $scriptDir = dirname( File::Spec->rel2abs( __FILE__ ) );
my $CONFIGFILE = $scriptDir . '/mapSwitches.config.yaml';

my $yaml = YAML::Tiny->new( \%config );
$yaml->write( $CONFIGFILE );
