Advertisement
Guest User

Infobl0x - checkGrid.pl

a guest
Oct 27th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 14.12 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. # [2016] Infobl0x, Inc.
  4. # All Rights Reserved.
  5. # NOTICE: All information contained herein is, and remains the property of Infoblox, Inc. and its suppliers, if any.
  6. # The intellectual and technical concepts contained herein are proprietary to Infoblox, Inc and its suppliers and may
  7. # be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.
  8. # Dissemination of this information or reproduction of this material is strictly forbidden unless prior written
  9. # permission is obtained from Infoblox, Inc.
  10.  
  11. use strict;
  12. use warnings;
  13. use Data::Dumper;
  14. $Data::Dumper::Indent = 3;
  15. use Infoblox;
  16.  
  17. my $login = (getpwuid $>);
  18. if ($login eq 'root') {
  19.     print "This script must NOT be run as root, remove the 'sudo' command.\n";
  20.     exit(66);
  21. }
  22.  
  23. my $ibhost = "10.100.0.100";
  24. my $ibuser = "api";
  25. my $ibpass = "Infobl0x";
  26.  
  27. # Setting up print styles
  28. my $error = "[\e[1;31m><\e[0m]";
  29. my $good = "[\e[0;32mOK\e[0m]";
  30. my $info = "[\e[1;37m--\e[0m]";
  31. my $warn = "[\e[1;33m!!\e[0m]";
  32. my $empty = "    ";
  33. my $dbug = "[\e[0;35m??\e[0m]";
  34.  
  35. # Functions that handle the print styles
  36. sub errorprint($) { print $error . " " . $_[0]; }
  37. sub goodprint($) { print $good . " " . $_[0]; }
  38. sub infoprint($) { print $info . " " . $_[0]; }
  39. sub warnprint($) { print $warn . " " . $_[0]; }
  40. sub emptyprint($) { print $empty . " " . $_[0]; }
  41. sub debugprint($) { if ((defined $ARGV[0]) && ($ARGV[0] eq "--debug")) { print $dbug . " " . $_[0];}}
  42. sub trim($) {
  43.     my $string = $_[0];
  44.     $string =~ s/^\s+//;
  45.     $string =~ s/\s+$//;
  46.     return $string;
  47. }
  48. my $hasissues = 0;
  49.  
  50. my $SESSION = Infoblox::Session->new(
  51.     'master'   => $ibhost,
  52.     'username' => $ibuser,
  53.     'password' => $ibpass,
  54. );
  55.  
  56. my %gridconfig = (
  57.     'grid_name'                      => "Infoblox",
  58.     'enable_ntp'                     => "true",
  59.     'ntp_address'                    => "10.100.0.10",
  60.     'time_zone'                      => "(UTC) Coordinated Universal Time",
  61.     'session_timeout'                => "7200",
  62.     'external_syslog_server_enabled' => "true",
  63.     'syslog_address'                 => "10.100.0.10",
  64.     'syslog_protocol'                => "udp",
  65.     'syslog_port'                    => "514",
  66.     'syslog_severity'                => "notice",
  67.     'copy_audit_to_syslog'           => "true",
  68.     'remote_console_access'          => "true",
  69.     'lcd_input'                      => "false",
  70.     'query_comm_string'              => "b4byBear",
  71.     'a1_name'                        => 'master.virtucon-trading.corp',
  72.     'a1_address'                     => '10.100.0.100',
  73.     'a1_subnet'                      => '255.255.255.0',
  74.     'a1_gateway'                     => '10.100.0.1',
  75.     'b1_name'                        => 'member1.virtucon-trading.corp',
  76.     'b1_address'                     => '10.200.0.105',
  77.     'b1_subnet'                      => '255.255.255.0',
  78.     'b1_gateway'                     => '10.200.0.1',
  79.     'b1_n1l1_address'                => '10.200.0.101',
  80.     'b1_n2l1_address'                => '10.200.0.102',
  81.     'b1_n1ha_address'                => '10.200.0.103',
  82.     'b1_n2ha_address'                => '10.200.0.104',
  83.     'b2_name'                        => 'member3.virtucon-trading.corp',
  84.     'b2_address'                     => '10.201.0.105',
  85.     'b2_subnet'                      => '255.255.255.0',
  86.     'b2_gateway'                     => '10.201.0.1',
  87. );
  88.  
  89. infoprint "Connecting to the Infoblox Grid...\n";
  90.  
  91. if ($SESSION->status_code()) {
  92.  
  93.     my $result = $SESSION->status_code();
  94.     my $response = $SESSION->status_detail();
  95.  
  96.     errorprint "API connection failed (" . $ibuser . '@' . $ibhost . ")\n";
  97.     errorprint $response . " (" . $result . ")\n";
  98.  
  99. } else {
  100.  
  101.     goodprint "API connection established (" . $ibuser . '@' . $ibhost . ")\n";
  102.     goodprint "Server Version: " . $SESSION->server_version() . "\n";
  103.  
  104.     print "\n";
  105.  
  106.     infoprint "Grid Configuration\n";
  107.  
  108.     my @grid_objs = $SESSION->get(
  109.         'object' => "Infoblox::Grid",
  110.         'name'   => $gridconfig{'grid_name'},
  111.     );
  112.  
  113.     my $grid = undef;
  114.  
  115.     # Check grid exists
  116.     if (scalar(@grid_objs) == 0) {
  117.         errorprint "Grid '" . $gridconfig{'grid_name'} . "' not found.\n";
  118.         exit(4);
  119.     } else {
  120.         goodprint "Grid '" . $gridconfig{'grid_name'} . "' found.\n";
  121.         $grid = $grid_objs[0];
  122.  
  123.         # check ntp is enabled and pointed at 10.100.0.10
  124.         if ($grid->enable_ntp() eq $gridconfig{'enable_ntp'}) {
  125.             goodprint "NTP is enabled\n";
  126.         } else {
  127.             errorprint "NTP is not enabled\n";
  128.             $hasissues = 1;
  129.         }
  130.  
  131.         my $ntp_server = $grid->ntp_server();
  132.         my @ntp_servers = @{$ntp_server};
  133.         if (scalar(@ntp_servers) == 1) {
  134.             if ($ntp_servers[0]->address() eq $gridconfig{'ntp_address'}) {
  135.                 goodprint "NTP server is " . $gridconfig{'ntp_address'} . "\n";
  136.             } else {
  137.                 errorprint "NTP is not configured correctly\n";
  138.                 debugprint "NTP server is " . $ntp_servers[0]->address() . "\n";
  139.                 $hasissues = 1;
  140.             }
  141.         } else {
  142.             errorprint "NTP is not configured correctly\n";
  143.             $hasissues = 1;
  144.         }
  145.  
  146.         # check timezone
  147.         my @tz = $SESSION->get("object" => "Infoblox::Grid::TimeZone");
  148.         if ($tz[0]->time_zone() eq $gridconfig{'time_zone'}) {
  149.             goodprint "Time zone is " . $gridconfig{'time_zone'} . "\n";
  150.         } else {
  151.             errorprint "Time zone is not configured correctly\n";
  152.             debugprint "Time zone is " . $tz[0]->time_zone() . "\n";
  153.             $hasissues = 1;
  154.         }
  155.  
  156.         # session timeout
  157.         if ($grid->session_timeout() eq $gridconfig{'session_timeout'}) {
  158.             goodprint "Session timeout is " . $gridconfig{'session_timeout'} . "\n";
  159.         } else {
  160.             errorprint "Session timeout is not configured correctly\n";
  161.             debugprint "Session timeout is " . $grid->session_timeout() . "\n";
  162.             $hasissues = 1;
  163.         }
  164.  
  165.         # LCD input
  166.         if ($grid->lcd_input() eq $gridconfig{'lcd_input'}) {
  167.             goodprint "LCD input is disabled\n";
  168.         } else {
  169.             errorprint "LCD input is not disabled\n";
  170.             $hasissues = 1;
  171.         }
  172.  
  173.         #snmp community string
  174.         if ($grid->remote_console_access() eq $gridconfig{'remote_console_access'}) {
  175.             goodprint "SSH access is enabled\n";
  176.         } else {
  177.             errorprint "SSH access is not enabled\n";
  178.             $hasissues = 1;
  179.         }
  180.  
  181.         #snmp community string
  182.         if ((defined $grid->query_comm_string()) && ($grid->query_comm_string() eq $gridconfig{'query_comm_string'})) {
  183.             goodprint "SNMP community is " . $gridconfig{'query_comm_string'} . "\n";
  184.         } else {
  185.             errorprint "SNMP community is not configured correctly\n";
  186.             $hasissues = 1;
  187.         }
  188.  
  189.         ## syslog
  190.         my $syslog_server = $grid->syslog_server();
  191.         if (defined $syslog_server) {
  192.             my @syslog_servers = @{$syslog_server};
  193.             if (scalar(@syslog_servers) == 1) {
  194.                 if ($syslog_servers[0]->address() eq $gridconfig{'syslog_address'}) {
  195.                     goodprint "External syslog server is " . $gridconfig{'syslog_address'} . "\n";
  196.                 } else {
  197.                     errorprint "External syslog server is not configured correctly\n";
  198.                     debugprint "External syslog server is " . $syslog_servers[0]->address() . "\n";
  199.                     $hasissues = 1;
  200.                 }
  201.  
  202.                 if ($syslog_servers[0]->connection_type() eq $gridconfig{'syslog_protocol'}) {
  203.                     goodprint "External syslog protocol is " . $gridconfig{'syslog_protocol'} . "\n";
  204.                 } else {
  205.                     errorprint "External Syslog protocol is not configured correctly\n";
  206.                     debugprint "External syslog protocol is " . $syslog_servers[0]->connection_type() . "\n";
  207.                     $hasissues = 1;
  208.                 }
  209.  
  210.                 if ($syslog_servers[0]->port() eq $gridconfig{'syslog_port'}) {
  211.                     goodprint "External syslog port is " . $gridconfig{'syslog_port'} . "\n";
  212.                 } else {
  213.                     errorprint "External syslog port is not configured correctly\n";
  214.                     debugprint "External syslog port is " . $syslog_servers[0]->port() . "\n";
  215.                     $hasissues = 1;
  216.                 }
  217.  
  218.                 if ($syslog_servers[0]->severity() eq $gridconfig{'syslog_severity'}) {
  219.                     goodprint "External syslog severity is " . $gridconfig{'syslog_severity'} . "\n";
  220.                 } else {
  221.                     errorprint "External syslog severity is not configured correctly\n";
  222.                     debugprint "External syslog severity is " . $syslog_servers[0]->severity() . "\n";
  223.                     $hasissues = 1;
  224.                 }
  225.  
  226.                 if ($syslog_servers[0]->only_category_list() eq "false") {
  227.                     goodprint "External syslog categories is All\n";
  228.                 } else {
  229.                     errorprint "External syslog categories is not configured correctly\n";
  230.                     $hasissues = 1;
  231.                 }
  232.  
  233.             } else {
  234.                 errorprint "External syslog is not configured correctly\n";
  235.                 $hasissues = 1;
  236.             }
  237.         } else {
  238.             errorprint "External syslog is not configured correctly\n";
  239.             $hasissues = 1;
  240.         }
  241.  
  242.         if ($grid->copy_audit_to_syslog() eq $gridconfig{'copy_audit_to_syslog'}) {
  243.             goodprint "Copy audit log to syslog is enabled\n";
  244.         } else {
  245.             errorprint "Copy audit log to syslog is not enabled\n";
  246.             $hasissues = 1;
  247.         }
  248.  
  249.         print "\n";
  250.         infoprint "Grid Master (A1) Configuration\n";
  251.         my @member_objs = $SESSION->get('object' => "Infoblox::Grid::Member", 'name' => $gridconfig{'a1_name'});
  252.         if (scalar(@member_objs) == 1) {
  253.  
  254.             goodprint "Member '" . $gridconfig{'a1_name'} . "' found\n";
  255.             my $member = $member_objs[0];
  256.  
  257.             # IP
  258.             if ($member->ipv4addr() eq $gridconfig{'a1_address'}) {
  259.                 goodprint "IP address is " . $gridconfig{'a1_address'} . "\n";
  260.             } else {
  261.                 errorprint "IP address is not configured correctly\n";
  262.                 debugprint "IP address is " . $member->ipv4addr() . "\n";
  263.                 $hasissues = 1;
  264.             }
  265.  
  266.             # subnet
  267.             if ($member->mask() eq $gridconfig{'a1_subnet'}) {
  268.                 goodprint "Subnet mask is " . $gridconfig{'a1_subnet'} . "\n";
  269.             } else {
  270.                 errorprint "Subnet mask is not configured correctly\n";
  271.                 debugprint "Subnet mask is " . $member->mask() . "\n";
  272.                 $hasissues = 1;
  273.             }
  274.  
  275.             # gw
  276.             if ($member->gateway() eq $gridconfig{'a1_gateway'}) {
  277.                 goodprint "Gateway is " . $gridconfig{'a1_gateway'} . "\n";
  278.             } else {
  279.                 errorprint "Gateway is not configured correctly\n";
  280.                 debugprint "Gateway is " . $member->gateway() . "\n";
  281.                 $hasissues = 1;
  282.             }
  283.  
  284.         } else {
  285.             errorprint "Member '" . $gridconfig{'a1_name'} . "' not found\n";
  286.             $hasissues = 1;
  287.         }
  288.  
  289.         print "\n";
  290.         infoprint "Grid Member (B1) Configuration\n";
  291.         @member_objs = $SESSION->get('object' => "Infoblox::Grid::Member", 'name' => $gridconfig{'b1_name'});
  292.         if (scalar(@member_objs) == 1) {
  293.  
  294.             goodprint "Member '" . $gridconfig{'b1_name'} . "' found\n";
  295.             my $member = $member_objs[0];
  296.  
  297.             # IP
  298.             if ($member->ipv4addr() eq $gridconfig{'b1_address'}) {
  299.                 goodprint "IP address is " . $gridconfig{'b1_address'} . "\n";
  300.             } else {
  301.                 errorprint "IP address is not configured correctly\n";
  302.                 debugprint "IP address is " . $member->ipv4addr() . "\n";
  303.                 $hasissues = 1;
  304.             }
  305.  
  306.             # subnet
  307.             if ($member->mask() eq $gridconfig{'b1_subnet'}) {
  308.                 goodprint "Subnet mask is " . $gridconfig{'b1_subnet'} . "\n";
  309.             } else {
  310.                 errorprint "Subnet mask is not configured correctly\n";
  311.                 debugprint "Subnet mask is " . $member->mask() . "\n";
  312.                 $hasissues = 1;
  313.             }
  314.  
  315.             # gw
  316.             if ($member->gateway() eq $gridconfig{'b1_gateway'}) {
  317.                 goodprint "Gateway is " . $gridconfig{'b1_gateway'} . "\n";
  318.             } else {
  319.                 errorprint "Gateway is not configured correctly\n";
  320.                 debugprint "Gateway is " . $member->gateway() . "\n";
  321.                 $hasissues = 1;
  322.             }
  323.  
  324.             # n1l1
  325.             if ((defined $member->node1_lan()) && ($member->node1_lan() eq $gridconfig{'b1_n1l1_address'})) {
  326.                 goodprint "Node 1 LAN1 IP address is " . $gridconfig{'b1_n1l1_address'} . "\n";
  327.             } else {
  328.                 errorprint "Node 1 LAN1 IP address is not configured correctly\n";
  329.                 debugprint "Node 1 LAN1 IP address is " . $member->node1_lan() . "\n";
  330.                 $hasissues = 1;
  331.             }
  332.  
  333.             # n2l1
  334.             if ((defined $member->node2_lan()) && ($member->node2_lan() eq $gridconfig{'b1_n2l1_address'})) {
  335.                 goodprint "Node 2 LAN1 IP address is " . $gridconfig{'b1_n2l1_address'} . "\n";
  336.             } else {
  337.                 errorprint "Node 2 LAN1 IP address is not configured correctly\n";
  338.                 debugprint "Node 2 LAN1 IP address is " . $member->node2_lan() . "\n";
  339.                 $hasissues = 1;
  340.             }
  341.  
  342.             # n1ha
  343.             if ((defined $member->node1_ha()) && ($member->node1_ha() eq $gridconfig{'b1_n1ha_address'})) {
  344.                 goodprint "Node 1 HA IP address is " . $gridconfig{'b1_n1ha_address'} . "\n";
  345.             } else {
  346.                 errorprint "Node 1 HA IP address is not configured correctly\n";
  347.                 debugprint "Node 1 HA IP address is " . $member->node1_ha() . "\n";
  348.                 $hasissues = 1;
  349.             }
  350.  
  351.             # n2ha
  352.             if ((defined $member->node2_ha()) && ($member->node2_ha() eq $gridconfig{'b1_n2ha_address'})) {
  353.                 goodprint "Node 2 HA IP address is " . $gridconfig{'b1_n2ha_address'} . "\n";
  354.             } else {
  355.                 errorprint "Node 2 HA IP address is not configured correctly\n";
  356.                 debugprint "Node 2 HA IP address is " . $member->node2_ha() . "\n";
  357.                 $hasissues = 1;
  358.             }
  359.  
  360.         } else {
  361.             errorprint "Member '" . $gridconfig{'b1_name'} . "' not found\n";
  362.             $hasissues = 1;
  363.         }
  364.  
  365.         print "\n";
  366.         infoprint "Grid Master (B2) Configuration\n";
  367.         @member_objs = $SESSION->get('object' => "Infoblox::Grid::Member", 'name' => $gridconfig{'b2_name'});
  368.         if (scalar(@member_objs) == 1) {
  369.  
  370.             goodprint "Member '" . $gridconfig{'b2_name'} . "' found\n";
  371.             my $member = $member_objs[0];
  372.  
  373.             # IP
  374.             if ($member->ipv4addr() eq $gridconfig{'b2_address'}) {
  375.                 goodprint "IP address is " . $gridconfig{'b2_address'} . "\n";
  376.             } else {
  377.                 errorprint "IP address is not configured correctly\n";
  378.                 debugprint "IP address is " . $member->ipv4addr() . "\n";
  379.                 $hasissues = 1;
  380.             }
  381.  
  382.             # subnet
  383.             if ($member->mask() eq $gridconfig{'b2_subnet'}) {
  384.                 goodprint "Subnet mask is " . $gridconfig{'b2_subnet'} . "\n";
  385.             } else {
  386.                 errorprint "Subnet mask is not configured correctly\n";
  387.                 debugprint "Subnet mask is " . $member->mask() . "\n";
  388.                 $hasissues = 1;
  389.             }
  390.  
  391.             # gw
  392.             if ($member->gateway() eq $gridconfig{'b2_gateway'}) {
  393.                 goodprint "Gateway is " . $gridconfig{'b2_gateway'} . "\n";
  394.             } else {
  395.                 errorprint "Gateway is not configured correctly\n";
  396.                 debugprint "Gateway is " . $member->gateway() . "\n";
  397.                 $hasissues = 1;
  398.             }
  399.  
  400.         } else {
  401.             errorprint "Member '" . $gridconfig{'b2_name'} . "' not found\n";
  402.             $hasissues = 1;
  403.         }
  404.     }
  405.  
  406.     print "\n";
  407.     if ($hasissues) {
  408.         warnprint "Your Grid configuration has issues, please fix and try again.\n";
  409.     } else {
  410.         goodprint "Your Grid configuration is correct.\n";
  411.     }
  412.  
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement