Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # [2016] Infobl0x, Inc.
- # All Rights Reserved.
- # NOTICE: All information contained herein is, and remains the property of Infoblox, Inc. and its suppliers, if any.
- # The intellectual and technical concepts contained herein are proprietary to Infoblox, Inc and its suppliers and may
- # be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.
- # Dissemination of this information or reproduction of this material is strictly forbidden unless prior written
- # permission is obtained from Infoblox, Inc.
- use strict;
- use warnings;
- use Data::Dumper;
- $Data::Dumper::Indent = 3;
- use Infoblox;
- my $login = (getpwuid $>);
- if ($login eq 'root') {
- print "This script must NOT be run as root, remove the 'sudo' command.\n";
- exit(66);
- }
- my $ibhost = "10.100.0.100";
- my $ibuser = "api";
- my $ibpass = "Infobl0x";
- # Setting up print styles
- my $error = "[\e[1;31m><\e[0m]";
- my $good = "[\e[0;32mOK\e[0m]";
- my $info = "[\e[1;37m--\e[0m]";
- my $warn = "[\e[1;33m!!\e[0m]";
- my $empty = " ";
- my $dbug = "[\e[0;35m??\e[0m]";
- # Functions that handle the print styles
- sub errorprint($) { print $error . " " . $_[0]; }
- sub goodprint($) { print $good . " " . $_[0]; }
- sub infoprint($) { print $info . " " . $_[0]; }
- sub warnprint($) { print $warn . " " . $_[0]; }
- sub emptyprint($) { print $empty . " " . $_[0]; }
- sub debugprint($) { if ((defined $ARGV[0]) && ($ARGV[0] eq "--debug")) { print $dbug . " " . $_[0];}}
- sub trim($) {
- my $string = $_[0];
- $string =~ s/^\s+//;
- $string =~ s/\s+$//;
- return $string;
- }
- my $hasissues = 0;
- my $SESSION = Infoblox::Session->new(
- 'master' => $ibhost,
- 'username' => $ibuser,
- 'password' => $ibpass,
- );
- my %gridconfig = (
- 'grid_name' => "Infoblox",
- 'enable_ntp' => "true",
- 'ntp_address' => "10.100.0.10",
- 'time_zone' => "(UTC) Coordinated Universal Time",
- 'session_timeout' => "7200",
- 'external_syslog_server_enabled' => "true",
- 'syslog_address' => "10.100.0.10",
- 'syslog_protocol' => "udp",
- 'syslog_port' => "514",
- 'syslog_severity' => "notice",
- 'copy_audit_to_syslog' => "true",
- 'remote_console_access' => "true",
- 'lcd_input' => "false",
- 'query_comm_string' => "b4byBear",
- 'a1_name' => 'master.virtucon-trading.corp',
- 'a1_address' => '10.100.0.100',
- 'a1_subnet' => '255.255.255.0',
- 'a1_gateway' => '10.100.0.1',
- 'b1_name' => 'member1.virtucon-trading.corp',
- 'b1_address' => '10.200.0.105',
- 'b1_subnet' => '255.255.255.0',
- 'b1_gateway' => '10.200.0.1',
- 'b1_n1l1_address' => '10.200.0.101',
- 'b1_n2l1_address' => '10.200.0.102',
- 'b1_n1ha_address' => '10.200.0.103',
- 'b1_n2ha_address' => '10.200.0.104',
- 'b2_name' => 'member3.virtucon-trading.corp',
- 'b2_address' => '10.201.0.105',
- 'b2_subnet' => '255.255.255.0',
- 'b2_gateway' => '10.201.0.1',
- );
- infoprint "Connecting to the Infoblox Grid...\n";
- if ($SESSION->status_code()) {
- my $result = $SESSION->status_code();
- my $response = $SESSION->status_detail();
- errorprint "API connection failed (" . $ibuser . '@' . $ibhost . ")\n";
- errorprint $response . " (" . $result . ")\n";
- } else {
- goodprint "API connection established (" . $ibuser . '@' . $ibhost . ")\n";
- goodprint "Server Version: " . $SESSION->server_version() . "\n";
- print "\n";
- infoprint "Grid Configuration\n";
- my @grid_objs = $SESSION->get(
- 'object' => "Infoblox::Grid",
- 'name' => $gridconfig{'grid_name'},
- );
- my $grid = undef;
- # Check grid exists
- if (scalar(@grid_objs) == 0) {
- errorprint "Grid '" . $gridconfig{'grid_name'} . "' not found.\n";
- exit(4);
- } else {
- goodprint "Grid '" . $gridconfig{'grid_name'} . "' found.\n";
- $grid = $grid_objs[0];
- # check ntp is enabled and pointed at 10.100.0.10
- if ($grid->enable_ntp() eq $gridconfig{'enable_ntp'}) {
- goodprint "NTP is enabled\n";
- } else {
- errorprint "NTP is not enabled\n";
- $hasissues = 1;
- }
- my $ntp_server = $grid->ntp_server();
- my @ntp_servers = @{$ntp_server};
- if (scalar(@ntp_servers) == 1) {
- if ($ntp_servers[0]->address() eq $gridconfig{'ntp_address'}) {
- goodprint "NTP server is " . $gridconfig{'ntp_address'} . "\n";
- } else {
- errorprint "NTP is not configured correctly\n";
- debugprint "NTP server is " . $ntp_servers[0]->address() . "\n";
- $hasissues = 1;
- }
- } else {
- errorprint "NTP is not configured correctly\n";
- $hasissues = 1;
- }
- # check timezone
- my @tz = $SESSION->get("object" => "Infoblox::Grid::TimeZone");
- if ($tz[0]->time_zone() eq $gridconfig{'time_zone'}) {
- goodprint "Time zone is " . $gridconfig{'time_zone'} . "\n";
- } else {
- errorprint "Time zone is not configured correctly\n";
- debugprint "Time zone is " . $tz[0]->time_zone() . "\n";
- $hasissues = 1;
- }
- # session timeout
- if ($grid->session_timeout() eq $gridconfig{'session_timeout'}) {
- goodprint "Session timeout is " . $gridconfig{'session_timeout'} . "\n";
- } else {
- errorprint "Session timeout is not configured correctly\n";
- debugprint "Session timeout is " . $grid->session_timeout() . "\n";
- $hasissues = 1;
- }
- # LCD input
- if ($grid->lcd_input() eq $gridconfig{'lcd_input'}) {
- goodprint "LCD input is disabled\n";
- } else {
- errorprint "LCD input is not disabled\n";
- $hasissues = 1;
- }
- #snmp community string
- if ($grid->remote_console_access() eq $gridconfig{'remote_console_access'}) {
- goodprint "SSH access is enabled\n";
- } else {
- errorprint "SSH access is not enabled\n";
- $hasissues = 1;
- }
- #snmp community string
- if ((defined $grid->query_comm_string()) && ($grid->query_comm_string() eq $gridconfig{'query_comm_string'})) {
- goodprint "SNMP community is " . $gridconfig{'query_comm_string'} . "\n";
- } else {
- errorprint "SNMP community is not configured correctly\n";
- $hasissues = 1;
- }
- ## syslog
- my $syslog_server = $grid->syslog_server();
- if (defined $syslog_server) {
- my @syslog_servers = @{$syslog_server};
- if (scalar(@syslog_servers) == 1) {
- if ($syslog_servers[0]->address() eq $gridconfig{'syslog_address'}) {
- goodprint "External syslog server is " . $gridconfig{'syslog_address'} . "\n";
- } else {
- errorprint "External syslog server is not configured correctly\n";
- debugprint "External syslog server is " . $syslog_servers[0]->address() . "\n";
- $hasissues = 1;
- }
- if ($syslog_servers[0]->connection_type() eq $gridconfig{'syslog_protocol'}) {
- goodprint "External syslog protocol is " . $gridconfig{'syslog_protocol'} . "\n";
- } else {
- errorprint "External Syslog protocol is not configured correctly\n";
- debugprint "External syslog protocol is " . $syslog_servers[0]->connection_type() . "\n";
- $hasissues = 1;
- }
- if ($syslog_servers[0]->port() eq $gridconfig{'syslog_port'}) {
- goodprint "External syslog port is " . $gridconfig{'syslog_port'} . "\n";
- } else {
- errorprint "External syslog port is not configured correctly\n";
- debugprint "External syslog port is " . $syslog_servers[0]->port() . "\n";
- $hasissues = 1;
- }
- if ($syslog_servers[0]->severity() eq $gridconfig{'syslog_severity'}) {
- goodprint "External syslog severity is " . $gridconfig{'syslog_severity'} . "\n";
- } else {
- errorprint "External syslog severity is not configured correctly\n";
- debugprint "External syslog severity is " . $syslog_servers[0]->severity() . "\n";
- $hasissues = 1;
- }
- if ($syslog_servers[0]->only_category_list() eq "false") {
- goodprint "External syslog categories is All\n";
- } else {
- errorprint "External syslog categories is not configured correctly\n";
- $hasissues = 1;
- }
- } else {
- errorprint "External syslog is not configured correctly\n";
- $hasissues = 1;
- }
- } else {
- errorprint "External syslog is not configured correctly\n";
- $hasissues = 1;
- }
- if ($grid->copy_audit_to_syslog() eq $gridconfig{'copy_audit_to_syslog'}) {
- goodprint "Copy audit log to syslog is enabled\n";
- } else {
- errorprint "Copy audit log to syslog is not enabled\n";
- $hasissues = 1;
- }
- print "\n";
- infoprint "Grid Master (A1) Configuration\n";
- my @member_objs = $SESSION->get('object' => "Infoblox::Grid::Member", 'name' => $gridconfig{'a1_name'});
- if (scalar(@member_objs) == 1) {
- goodprint "Member '" . $gridconfig{'a1_name'} . "' found\n";
- my $member = $member_objs[0];
- # IP
- if ($member->ipv4addr() eq $gridconfig{'a1_address'}) {
- goodprint "IP address is " . $gridconfig{'a1_address'} . "\n";
- } else {
- errorprint "IP address is not configured correctly\n";
- debugprint "IP address is " . $member->ipv4addr() . "\n";
- $hasissues = 1;
- }
- # subnet
- if ($member->mask() eq $gridconfig{'a1_subnet'}) {
- goodprint "Subnet mask is " . $gridconfig{'a1_subnet'} . "\n";
- } else {
- errorprint "Subnet mask is not configured correctly\n";
- debugprint "Subnet mask is " . $member->mask() . "\n";
- $hasissues = 1;
- }
- # gw
- if ($member->gateway() eq $gridconfig{'a1_gateway'}) {
- goodprint "Gateway is " . $gridconfig{'a1_gateway'} . "\n";
- } else {
- errorprint "Gateway is not configured correctly\n";
- debugprint "Gateway is " . $member->gateway() . "\n";
- $hasissues = 1;
- }
- } else {
- errorprint "Member '" . $gridconfig{'a1_name'} . "' not found\n";
- $hasissues = 1;
- }
- print "\n";
- infoprint "Grid Member (B1) Configuration\n";
- @member_objs = $SESSION->get('object' => "Infoblox::Grid::Member", 'name' => $gridconfig{'b1_name'});
- if (scalar(@member_objs) == 1) {
- goodprint "Member '" . $gridconfig{'b1_name'} . "' found\n";
- my $member = $member_objs[0];
- # IP
- if ($member->ipv4addr() eq $gridconfig{'b1_address'}) {
- goodprint "IP address is " . $gridconfig{'b1_address'} . "\n";
- } else {
- errorprint "IP address is not configured correctly\n";
- debugprint "IP address is " . $member->ipv4addr() . "\n";
- $hasissues = 1;
- }
- # subnet
- if ($member->mask() eq $gridconfig{'b1_subnet'}) {
- goodprint "Subnet mask is " . $gridconfig{'b1_subnet'} . "\n";
- } else {
- errorprint "Subnet mask is not configured correctly\n";
- debugprint "Subnet mask is " . $member->mask() . "\n";
- $hasissues = 1;
- }
- # gw
- if ($member->gateway() eq $gridconfig{'b1_gateway'}) {
- goodprint "Gateway is " . $gridconfig{'b1_gateway'} . "\n";
- } else {
- errorprint "Gateway is not configured correctly\n";
- debugprint "Gateway is " . $member->gateway() . "\n";
- $hasissues = 1;
- }
- # n1l1
- if ((defined $member->node1_lan()) && ($member->node1_lan() eq $gridconfig{'b1_n1l1_address'})) {
- goodprint "Node 1 LAN1 IP address is " . $gridconfig{'b1_n1l1_address'} . "\n";
- } else {
- errorprint "Node 1 LAN1 IP address is not configured correctly\n";
- debugprint "Node 1 LAN1 IP address is " . $member->node1_lan() . "\n";
- $hasissues = 1;
- }
- # n2l1
- if ((defined $member->node2_lan()) && ($member->node2_lan() eq $gridconfig{'b1_n2l1_address'})) {
- goodprint "Node 2 LAN1 IP address is " . $gridconfig{'b1_n2l1_address'} . "\n";
- } else {
- errorprint "Node 2 LAN1 IP address is not configured correctly\n";
- debugprint "Node 2 LAN1 IP address is " . $member->node2_lan() . "\n";
- $hasissues = 1;
- }
- # n1ha
- if ((defined $member->node1_ha()) && ($member->node1_ha() eq $gridconfig{'b1_n1ha_address'})) {
- goodprint "Node 1 HA IP address is " . $gridconfig{'b1_n1ha_address'} . "\n";
- } else {
- errorprint "Node 1 HA IP address is not configured correctly\n";
- debugprint "Node 1 HA IP address is " . $member->node1_ha() . "\n";
- $hasissues = 1;
- }
- # n2ha
- if ((defined $member->node2_ha()) && ($member->node2_ha() eq $gridconfig{'b1_n2ha_address'})) {
- goodprint "Node 2 HA IP address is " . $gridconfig{'b1_n2ha_address'} . "\n";
- } else {
- errorprint "Node 2 HA IP address is not configured correctly\n";
- debugprint "Node 2 HA IP address is " . $member->node2_ha() . "\n";
- $hasissues = 1;
- }
- } else {
- errorprint "Member '" . $gridconfig{'b1_name'} . "' not found\n";
- $hasissues = 1;
- }
- print "\n";
- infoprint "Grid Master (B2) Configuration\n";
- @member_objs = $SESSION->get('object' => "Infoblox::Grid::Member", 'name' => $gridconfig{'b2_name'});
- if (scalar(@member_objs) == 1) {
- goodprint "Member '" . $gridconfig{'b2_name'} . "' found\n";
- my $member = $member_objs[0];
- # IP
- if ($member->ipv4addr() eq $gridconfig{'b2_address'}) {
- goodprint "IP address is " . $gridconfig{'b2_address'} . "\n";
- } else {
- errorprint "IP address is not configured correctly\n";
- debugprint "IP address is " . $member->ipv4addr() . "\n";
- $hasissues = 1;
- }
- # subnet
- if ($member->mask() eq $gridconfig{'b2_subnet'}) {
- goodprint "Subnet mask is " . $gridconfig{'b2_subnet'} . "\n";
- } else {
- errorprint "Subnet mask is not configured correctly\n";
- debugprint "Subnet mask is " . $member->mask() . "\n";
- $hasissues = 1;
- }
- # gw
- if ($member->gateway() eq $gridconfig{'b2_gateway'}) {
- goodprint "Gateway is " . $gridconfig{'b2_gateway'} . "\n";
- } else {
- errorprint "Gateway is not configured correctly\n";
- debugprint "Gateway is " . $member->gateway() . "\n";
- $hasissues = 1;
- }
- } else {
- errorprint "Member '" . $gridconfig{'b2_name'} . "' not found\n";
- $hasissues = 1;
- }
- }
- print "\n";
- if ($hasissues) {
- warnprint "Your Grid configuration has issues, please fix and try again.\n";
- } else {
- goodprint "Your Grid configuration is correct.\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement