Subversion Repositories sysadmin_scripts

Rev

Rev 128 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 rodolico 1
#! /usr/bin/env perl
2
 
3
# just a simple script for people more familiar with
4
# perl syntax than YAML. Modify %config below, then run
5
# this script. It will create the configuration file for
6
# you.
7
use strict;
8
use warnings;
9
 
10
use YAML::Tiny; # apt-get libyaml-tiny-perl under debian
11
use File::Spec; # find location of script so we can put storage in same directory
12
use File::Basename;
13
 
14
 
15
my %config = (
16
      # one or more switches and their corresponding
17
      # community name. Use v1 snmp only
18
      'switches' => {
66 rodolico 19
         'DNS or IP' => { # enter a DNS name or an IP address to be scanned.
5 rodolico 20
            'community' => 'snmp community name',
66 rodolico 21
            # the following list can be used to ignore ports on this switch. Note that these are the port numbers
22
            # returned by OID iso.3.6.1.2.1.2.2.1.8
69 rodolico 23
            'portsToIgnore' => ['port','numbers','to','ignore']
5 rodolico 24
         },
25
         'DNS or IP' => {
26
            'community' => 'snmp community name',
69 rodolico 27
            'portsToIgnore' => ['port','numbers','to','ignore']
5 rodolico 28
         }
29
      },
30
      # You must include at least one router.
31
      # this will be queried to resolve IP's to MAC 
32
      # using its arp table
33
      # put IP and community name into the hash
34
      'routers' =>  {
35
            'DNS or IP' => {
36
               'community' => 'snmp community name',
37
            },
38
            'DNS or IP' => {
39
               'community' => 'snmp community name',
40
            }
69 rodolico 41
      },
42
      # this is entire optional, but if it exists, it will be used to supplement or override MAC to IP to DNS lookup.
43
      # Each entry is optional
44
      # MAC is the hexidecimal mac address, with no delimiters and all lower case. Example is: 
45
      #    402cf4e9ae9b      CORRECT
46
      #    40:2c:f4:e9:ae:9b WRONG, has delimiters (the colons)
47
      #    402CF4E9AE9B      WRONG, alphas are upper case
48
      # ip:       if this is entered, will be used as IP for the mac address, otherwise it is looked up in the routers arp table.
49
      #           default is to get IP from router's arp table
50
      # hostname: If this is entered, will be used for hostname, otherwise done via reverse DNS entry from router. Default is
51
      #           to look up via rdns
52
      # override: If false, ip/hostname only be used if no value returned from arp/rdns. If true, ip/hostname are not even
53
      #           attempted, ie this will override anything in those services. Default is false, only use if you can not find
54
      #           it.
55
      'staticmaps' => {
56
         'MAC1' => {
57
            'ip' => '1.1.1.1',
58
            'hostname' => 'some.host.name',
59
            'override' => 0
60
            },
61
         'MAC2' => {
62
            'ip' => '1.1.1.2',
63
            'hostname' => 'some other host name',
64
            'override' => 1
65
         }
128 rodolico 66
      },
136 rodolico 67
      # Optional files to be processed for items which were not in the router
68
      # these are assumed to be tab delimited files which contain the column
69
      # headers 'hostname', 'mac' and 'ip', with values below
70
      # this can be done via staticmaps (above), but is set up as an alternative
71
      # here for very large files, say from database dumps
72
      # files are assumed to be in the script directory
128 rodolico 73
      'nonrouter' => (
74
         'filename1',
75
         'filename2'
136 rodolico 76
      ),
77
      # instead of doing all of the snmp walks, if refresh is set, it will only check the
78
      # switch ports to see if they have changed MAC addresses. Once every 'refresh' time
79
      # a full rescan of port names, switch names, and rdns look ups will occur
80
      # using this cuts the time to run by about 1/3      
81
      'refresh' => 'seconds',
82
      # If set, entries which have not been seen for this period of time
83
      # are removed. Modifiers are h, d, w, m, y (hours, days, weeks, months, years)
84
      'ttl' => 'seconds'
128 rodolico 85
 
69 rodolico 86
 
87
 
5 rodolico 88
   );
89
 
90
my $scriptDir = dirname( File::Spec->rel2abs( __FILE__ ) );
91
my $CONFIGFILE = $scriptDir . '/mapSwitches.config.yaml';
92
 
93
my $yaml = YAML::Tiny->new( \%config );
94
$yaml->write( $CONFIGFILE );