Adding a Asset "All-In-One" Access Panel for Device Details Dashboard

Garrett Caudle

Adding quick access buttons to device details dashboard

-This set of scripts  runs against all devices in a groups you define that you wish for them to appear. There is also a dynamic context to it where as additional button(s) could appear for devices meeting a certain criteria, in this case being in a device group.

 

!--Use at your own risk! It works great for me, but each environment is different so please validate in test environment. Also, I am new to perl and I am sure there are better ways to handle this script and I am sure there are some errors in the code I missed while sanitizing it so again, please test and validate first--!

 

Use Case: Needed a way to place an entire sites devices in/out of maintenance mode quickly. Also, the environment I am in has other tools for network management as well as just wanting quick access buttons for other useful AKIPs Reports/Tools relevant to the device details being viewed and accessing them all separately was painful. The need for having all tools accessible on a single screen was needed so I created this script to place a new row of buttons on device details dashboard giving quick access links to the currently viewed devices's…

 

(Internal AKIPs Links filtered for device)

-CDP Neighbors

-Events related to device for last8h

-Syslog messages from device for last2h

-Device Serial Number (string, not a link)

 

 

External Tools (These are specific to my specific use case and example only)

-Backups of device config

Dynamic Links (when devices are in specific groups)

-"WAN" Group: Link to data circuit management database filtered for site's circuits (filter is using fist 2 characters of device's hostname which represents site code)

-"Site-Core-Devices" Group: If a device was a site's core, links  titled "Site Wide Maintenance Mode-Enable/Disable" would appear that when clicked would execute site scripts putting all devices with the same first 2 characters in device name which represents a site code,  into or out of maintenance mode.

 

################# BEGIN AIO PANEL ################################

#

############ BEGIN PROD ADD AIO PANEL ASSET+RESOURCE #############

# -----------------------------------------------------------------------------

# config_asset_all_in_one

# Collapse "resources" into the single 'asset' child so links show in header.

#   asset:

#     - Oxidized URL for device's config backup

#     - CDP Neighbor AKIPs report link

#     - Device specific related Events (last 8 hours) AKIPs Tool link

#     - Conditional group links

#     - Serial_Num (ENTITY-MIB)

#     - Syslog AKIPs viewer link

#     - Site wide enable/disable maintenance mode links for core devices

 

 

# -----------------------------------------------------------------------------

 

sub config_asset_all_in_one {

 

  # ====================== SETTINGS ===========================================

  # Oxidized

  my $OXI_BASE    = "http://oxidized.net:8888/node/show/";  

  my $OXI_BY      = "hostname";    # "hostname" or "ip"

 

  use URI::Escape qw(uri_escape);

 

  # AKiPS report links

  my $ADD_CDP     = 1;

  my $ADD_EVENTS    = 1;

  my $ADD_LOGS    = 1;

 

  # Visual section headers

  my $ADD_HEADERS = 1;

 

  # Replace existing 'asset' content each run (scoped to device)

  my $DO_DELETE_ASSET = 1;

 

  my $is_site_core = 0;

 

  # --------- FILTERS ---------------------------------------------------------

  # Exact device allowlist. If non-empty, only these are processed.

  my @DEVICES = ();   # e.g., ("")

 

  # Limit to these AKiPS Groups (exact names). Empty => all devices with IPv4.

  my @GROUPS  = ("Cisco", "Aruba");   # e.g., ("Wireless","Cisco")

 

  my @WAN_GROUPS = ("WAN_Aggregation", "Wan_Interfaces"");

 

  # Conditional links by Group membership (label/url per group)

  my %GROUP_LINKS = (

    "Tool-Test-Devices" => [

      { label => "My custom tool 1", url => "https://wirelessTool.com/" },

      { label => "My custom tool 2", url => "https://otherTool.com" },

      # Add more tools here…

    ],

    "WAN" => [ { label=>"Circuit Portal", url=>"https://carrier.portal/" } ],

  );

  # ==========================================================================

 

  my (@dev_lines, %seen);

 

  # ---- Build candidate list -------------------------------------------------

  if (@DEVICES) {

    for my $d (@DEVICES) {

      my @lines = adb_result(sprintf("mget * %s sys ip4addr", $d));

      push @dev_lines, @lines;

    }

  } elsif (@GROUPS) {

    for my $g (@GROUPS) {

      my @lines = adb_result(sprintf("mget * * sys ip4addr any group %s", $g));

      for my $ln (@lines) {

        my @a = split(" ", $ln, 5);

        my $dev = $a[0];

        next if $seen{$dev}++;

        push @dev_lines, $ln;

      }

    }

  } else {

    @dev_lines = adb_result("mget * * sys ip4addr");

  }

 

  # ---- Process each device in the above listed groups--------------------------------------------------

  for my $line (@dev_lines) {

    my @arr = split(" ", $line, 5);

    my $dev = $arr[0];

    my $ip  = $arr[4] || "";

 

    # Reset/ensure single 'asset' child

    if ($DO_DELETE_ASSET) {

      adb_send(sprintf("mdelete * %s asset", $dev));

    }

    adb_send(sprintf("add child %s asset", $dev));

   

  # === Group check: Build group map + core flag ===

  # === Get groups for this device ===

    my %group_map;

    my @device_groups = adb_result("list device group $dev");

 

    foreach my $group (@device_groups) {

      $group_map{$group} = 1;

    }

    # Check if device is a site core

    my $is_site_core = exists $group_map{"Site-Core-Devices"};

 

   

  # ----- Section: Site Maintenance Mode Toggle Links  -----------------------------------------

 

  # ==== Here we define the URL of your AKIPs node and API password for user "api-rw" to call our site-scripts to toggle maint mode ====

 

  if ($is_site_core) {

    my $api_password = "myAPIpassword";

    my $server = "akips-test.net";  # or your actual AKiPS server FQDN

 

    # ==== Here we build and call the URLs to trigger the site scripts for main mode toggling using site_code we collect here ====

  my $site_code = substr($dev, 0, 2);  # e.g., "AB"

  my $on_url  = "/api-script?password=$api_password;function=web_aio_toggle_site_maint_mode;toggle=ON;site=$site_code";

  my $off_url = "/api-script?password=$api_password;function=web_aio_toggle_site_maint_mode;toggle=OFF;site=$site_code";

 

  adb_send(sprintf(

    "add text %s asset Maint_ON = \"<a href='%s' target='_blank'>Enable Site Maintenance</a>\"",

    $dev, $on_url

  ));

 

  adb_send(sprintf(

    "add text %s asset Maint_OFF = \"<a href='%s' target='_blank'>Disable Site Maintenance</a>\"",

    $dev, $off_url

  ));

 

# === EXAMPLE USE CASE SHOWING DYNAMIC BUTTON LOGIC--- if in group "WAN" device CRM Link logic ===

 

  for my $wan_group (@WAN_GROUPS) {

    if ($group_map{$wan_group}) {

      my $loc = substr($dev, 0, 2);

      my $crm_url = "http://suitecrm.net/#/contracts/index"

                  . "?return_module=AOS_Contracts"

                  . "&return_action=DetailView"

                  . "&query=true"

                  . "&fp_event_locations_aos_contracts_1_name=$loc";

    adb_send(sprintf("add text %s asset WAN_CRM = \"<a href='%s' target='_blank'>CRM</a>\"", $dev, $crm_url));

    last;

  }

}

}

 

    # ----- Section: Access & Reports -----------------------------------------

 

    # Oxidized Config Backups Version Control link

    my $node_key = ($OXI_BY eq "ip") ? (($ip ne "") ? $ip : $dev) : $dev;

    my $oxi_url  = $OXI_BASE . $node_key;

    adb_send(sprintf(

      "add text %s asset CFG-BACKUP = \"<a href='%s' target='_blank'>Oxidized Config</a>\"",

      $dev, $oxi_url

    ));

 

    # CDP/EVENTS report links

    if ($ADD_CDP) {

      adb_send(sprintf(

        "add text %s asset CDP = \"<a href='/device-reporter?report=cisco.cdp;mode=report;controls=device;time=last30m;limit=100;group_regex=;device_group=;device_list=%s' target='_blank'>CDP</a>\"",

        $dev, $dev

      ));

    }

    if ($ADD_EVENTS) {

      adb_send(sprintf(

        "add text %s asset EVENTS = \"<a href='/event-reporter?mode=table graph;time=last8h;limit=100;device_group=;device_list=%s' target='_blank'>EVENTS</a>\"",

        $dev, $dev

      ));

    }

   

    if ($ADD_LOGS) {

      adb_send(sprintf(

        "add text %s asset EVENTS = \"<a href='/msg-reporter?mode=table%20graph;type=syslog;time=last2h;save_rules=on;limit=1000;af=%s;' target='_blank'>EVENTS</a>\"",

        $dev, $dev

      ));

    }

 

    # ----- Section: Inventory -------------------------------------------------

 

    # Serial Number (ENTITY-MIB)

    my $serial = "missing";

    my @ser_lines = adb_result(sprintf("mget * %s * serial", $dev));

    for my $sline (@ser_lines) {

      my @sarr = split(" ", $sline, 5);

      my $val  = $sarr[4] || "";

      if ($val ne "") { $serial = $val; last; }

    }

    adb_send(sprintf("add text %s asset Serial_Num = \"%s\"", $dev, $serial));

}

 

  adb_flush();

}

 

# sanitize label -> attribute key

sub _safe_key {

  my ($s) = @_;

  $s =~ s/[^A-Za-z0-9_]+/_/g;

  return $s;

}

############ END PROD ADD AIO PANEL ASSET+RESOURCE #############

#

####### BEGIN AIO PANEL TOGGLE SITE MAINT MODE FEATURE #########

 

# This script is a component of the above AIO panel-Do not use

# independantly!

 

sub web_aio_toggle_site_maint_mode {

  use strict;

  use warnings;

 

  my $ERR_INFO  = 1;

  my $ERR_WARN  = 2;

  my $ERR_ERROR = 3;

  my $ERR_FATAL = 4;

 

  my $type  = "device";

  my $maint_group = "maintenance_mode";

 

  # === Decode URL parameters ===

  cgi_decode(); 

 

  # === Get parameters ===

  my $toggle_maint_mode = cgi_param("toggle") || "";

  my $site_code = cgi_param("site") || "";

 

  $toggle_maint_mode = uc($toggle_maint_mode);

  $site_code = uc($site_code);

 

  unless ($toggle_maint_mode eq "ON" || $toggle_maint_mode eq "OFF") {

    errlog($ERR_WARN, "Invalid toggle value: '$toggle_maint_mode'");

    return;

  }

 

  unless ($site_code =~ /^[A-Z0-9]{2}$/) {

    errlog($ERR_WARN, "Invalid or missing site code: '$site_code'");

    return;

  }

 

  errlog($ERR_INFO, "Toggling maintenance mode '$toggle_maint_mode' for site code: $site_code");

 

  # === Get all devices and match by site prefix ===

  my @lines = adb_result("mget * * sys ip4addr");

  my @site_devices;

 

  foreach my $line (@lines) {

    my @parts = split(" ", $line);

    my $dev = $parts[0] || next;

 

    if (substr($dev, 0, 2) eq $site_code) {

      push @site_devices, $dev;

    }

  }

 

  group_manual_load_cfg();

 

  if ($toggle_maint_mode eq "ON") {

    foreach my $dev (@site_devices) {

      errlog($ERR_INFO, "Putting $dev into maintenance mode");

      group_manual_assign($type, $dev, $maint_group);

    }

  } elsif ($toggle_maint_mode eq "OFF") {

    foreach my $dev (@site_devices) {

      errlog($ERR_INFO, "Removing $dev from maintenance mode");

      group_manual_clear($type, $dev, $maint_group);

    }

  }

 

  group_manual_save_cfg();

  adb_flush();

}

 

 

####### END AIO PANEL TOGGLE SITE MAINT MODE FEATURE #########

#################### END AIO PANEL  ##########################

Comments

0 comments

Please sign in to leave a comment.