THWACK logo
THWACK
  • Sign In
  • Search
  • Community
    Community

    Find all you need to begin your THWACK journey, including documentation, missions, blogs, community groups, events, and media.

    Command Central
    • Getting Started
    MVP Program
    • MVP Program
    Monthly Mission
    • Hidden Gems
    Blogs
    • Community Announcements
    • Product Blog
    Groups
    • DevOps Discourse
    • Data Driven
    • See All Groups
    Events
    • SolarWinds User Group
    • THWACKcamp
      • ↪ 2024: On Demand
    • Bracket Battle
    Media Vault
    • Movies & Mainframes
    • TechPod
    • THWACK Tech Tips
    • THWACK Livecast
    • SolarWinds Lab Archive
    • THWACKcamp Archive
    • See All Media
  • Products
    Products

    Find the best place to learn and ask questions about your SolarWinds products.

    Observability
    • Observability Solutions
    • SolarWinds Observability SaaS
    • SolarWinds Observability Self-Hosted
    • SolarWinds Platform
    Network Management
    • Network Performance Monitoring
    • NetFlow Traffic Analyzer
    • Network Configuration Manager
    • IP Address Manager
    • User Device Tracker
    • VoIP & Network Quality Manager
    • Log Analyzer
    • Engineer's Toolset
    • Network Topology Mapper
    • Kiwi CatTools
    • Kiwi Syslog Server
    • ipMonitor
    Application Management
    • AppOptics
    • Loggly
    • Papertrail
    • Pingdom
    • DevOps
    IT Security
    • Access Rights Manager
    • Identity Monitor
    • Security Event Manager
    • Patch Manager
    • Serv-U FTP & MFT
    IT Service Management
    • SolarWinds Service Desk
    • Web Help Desk
    • DameWare Remote Support
    • DameWare Remote Everywhere
    • DameWare Mini Remote Control
    System Management
    • Server & Application Monitor
    • Virtualization Manager
    • Storage Resource Monitor
    • Server Configuration Monitor
    • SolarWinds Backup
    • Web Performance Monitor
    Database Management
    • Database Performance Analyzer
    • SQL Sentry
    • Database Performance Monitor
    • Database Mapper
    • Task Factory
  • Content Exchange
    Content Exchange

    Find downloadable files and templates other users have built and found useful to share with others.

    SolarWinds Platform
    • Alerts
    • Custom HTML
    • Custom Queries
    • Modern Dashboards
    • Reports
    • Scripts
    Server & Application Monitor
    • API Pollers
    • Application Monitor Templates
    Database Performance Analyzer
    • Custom Alerts
    • Custom Metrics
    • Custom Queries
    Server Configuration Monitor
    • Policies
    • Profiles
    Network Performance Monitor
    • Device Pollers
    • Universal Device Pollers
    Network Configuration Manager
    • Config Change Scripts
    • Device Templates
    • Firmware Upgrade Templates
    • Policy Documents
    SQL Sentry
    • Advisory Conditions
    Web Help Desk
    • Style Sheets
  • Resources
    SolarWinds Customer Portal Customer Portal

    Create individual user accounts for your team, manage your licenses, download your SolarWinds software, create and track support tickets, and more.

    SolarWinds Academy Academy

    A one-stop-shop for world-class training for SolarWinds products through on-demand videos, and instructor-led classes. All SolarWinds Academy content is included with every software purchase.

    SolarWinds Customer Success Support

    Get help when you need it from a world-class support team, available to assist with technical product issues 24 hours a day, seven days a week, 365 days a year.

    SolarWinds Partner Portal Partner Portal

    Accelerate SolarWinds Partners’ ability to drive digital and IT transformation for customers with powerful tools, resources, and increased profit potential.

  • Free Tools & Trials
  • Store
The SolarWinds Platform
  • Products
The SolarWinds Platform
SolarWinds Platform API Enhancing Custom Query Widgets
  • Newsroom
  • Forums
  • SolarWinds Platform API
  • Content Exchange
  • What We're Working On
  • Feature Requests
  • More
  • Cancel
  • New
  • -SolarWinds Platform API
    • About the SolarWinds Information Service (SWIS)
    • +Setting up a Python Development Environment
    • +Using PowerShell 7+ and Visual Studio Code
    • +SolarWinds Query Language (SWQL) Basics
    • -Data Presentation Examples
      • Enhancing Custom Query Widgets
      • Poor Man's PIVOT
      • Potential Gotchas
      • Returning the Most Recent Element from a Related Entity
      • Working with Dates
    • Additional Resources
    • Glossary

Enhancing Custom Query Widgets

The custom query widget is one of the most flexible extensions for Classic Dashboards, allowing you to present your data in any way you see fit.  The data represented can be anything stored within the SolarWinds Platform, but for the sake of examples, we'll begin with the simple scenario where you want to show all of your "Up" nodes and their CPU utilization.

Modern Dashboards extend the capabilities of Custom Query Widgets. The Custom Query Widget is a function of Classic Dashboards, though the good habits and syntax apply to both.

Our Starting Query

We'll start with a simple query asking for the "up" nodes and their current CPU Utilization.

SELECT [Nodes].DisplayName
     , [Nodes].CPULoad
FROM Orion.Nodes AS [Nodes]
WHERE [Nodes].Status = 1 -- a Status of 1 indicates 'Up' (See Orion.StatusInfo for a complete list)
  AND [Nodes].External = False -- (Not External)
  AND [Nodes].ObjectSubType <> 'ICMP' -- (Not ICMP)
  -- some very specific devices do not report their CPU, so we'll skip them.
  AND ( [Nodes].CPUCount IS NOT NULL 
     OR [Nodes].CPULoad < 0
      ) 
-- We'll sort by Caption/DisplayName because it's convenient
ORDER BY [Nodes].DisplayName

Placing the above query in a custom query widget will product output based on your environment.

Custom Query Widget with Name and CPU Load

Extending with Icons via Macros

The data returned looks good but isn't very visually appealing.  It would be nicer if we could add a few icons- perhaps representing the status or the type of device.

Native to the SolarWinds Platform, there is a macro called _IconFor_ and it's used in our example below.

SELECT [Nodes].DisplayName
     , [Nodes].CPULoad
       -- add the icon for 'DisplayName' from the Vendor Icon
     , [Nodes].VendorIcon AS [_IconFor_DisplayName]
       -- the rest of the query does not change
FROM Orion.Nodes AS [Nodes]
WHERE [Nodes].Status = 1 -- 1 = 'Up' (See Orion.StatusInfo for a complete list)
  AND [Nodes].External = False -- (Not External)
  AND [Nodes].ObjectSubType <> 'ICMP' -- (Not ICMP)
  -- some very specific devices do not report their CPU, so we'll skip them.
  AND [Nodes].CPUCount IS NOT NULL 
-- We'll sort by Caption/DisplayName because it's convenient
ORDER BY [Nodes].DisplayName

Which changes our displayed output to:

Output of Custom Query Widget with Vendor Icon (broken)

Well, that's less than helpful.  This is because the vendor icons aren't stored in the root of the website, they exist in a subfolder.  We'll need to prepend the icon name with the path to the folder containing these icons.  The easiest way to do this is to find a known good icon on another page and find the path. This can be done multiple way, but I've found the easiest to look at the code behind the page.

We don't want the full URL, just the relative URL, which for Vendor Icons is /NetPerfMon/Images/Vendors/<vendorIconFileName>.  We can update our query to include this.  This can be done with either the string addition operator (+) or concatenation function.

When working with URLs, it's best practice to use the concatenation function to create the URLs. The CONCAT() function automatically changes the types of all elements to strings before combining them. If you were to use the addition operator (+) and execute ( String + Integer ), you would get a type error. However, if the same was done with CONCAT(String, Integer), the integer would be converted to a string and then concatenated to the other strings.

SELECT [Nodes].DisplayName
     , [Nodes].CPULoad
       -- add the icon for 'DisplayName' from the Vendor Icon
     , CONCAT('/NetPerfMon/Images/Vendors/', [Nodes].VendorIcon) AS [_IconFor_DisplayName]
FROM Orion.Nodes AS [Nodes]
WHERE [Nodes].Status = 1 -- 1 = 'Up' (See Orion.StatusInfo for a complete list)
  AND [Nodes].External = False -- (Not External)
  AND [Nodes].ObjectSubType <> 'ICMP' -- (Not ICMP)
  -- some very specific devices do not report their CPU, so we'll skip them.
  AND [Nodes].CPUCount IS NOT NULL 
-- We'll sort by Caption/DisplayName because it's convenient
ORDER BY [Nodes].DisplayName

After submitting that change, the custom query widget would render correctly.

Custom Query Widget with Name, CPU Load, and Vendor Icon

There are many, many options available: Alert Status, Events, Volumes, Interfaces, and Node Status icons.  This is a table of some of the icons available for your disposal.

Item Type URL Format Example
Alert Status /Orion/images/ActiveAlerts/<StatusName>.png /Orion/images/ActiveAlerts/Critical.png
Events by ID /NetPerfMon/images/Event-<EventID>.gif /NetPerfMon/images/Event-5001.gif
Volumes by Type /NetPerfMon/images/Volumes/<VolumeType>.gif /NetPerfMon/images/Volumes/FixedDisk.gif
Interfaces by Type ID /NetPerfMon/images/Interfaces/<InterfaceTypeID>.gif /NetPerfMon/images/Interfaces/6.gif
Status (Extended) /Orion/StatusIcon.ashx?entity=<EntityType>&status=<StatusID>&size=<small/large> /Orion/StatusIcon.ashx?entity=Orion.APM.ActiveDirectory.Component&status=1&size=small

If there's an icon in the web console, you'd like to use, you just need to find the relative URL for the _IconFor_ macro and build it together.

Since each _LinkFor_ macro needs to be directly associated with a returned field name, you cannot choose two different (Vendor and Status) icons. Use your best judgment based on the use of the Custom Query Widget.

Extending with Links via Macros

As nice as this listing is, it would be better if it was interactive. For this purpose, the Custom Query Widget has a _LinkFor_ macro we can utilize.  Let's link the Node's display name to the details page.

SELECT [Nodes].DisplayName
     , [Nodes].CPULoad
       -- add the icon for 'DisplayName' from the Vendor Icon
     , CONCAT('/NetPerfMon/Images/Vendors/', [Nodes].VendorIcon) AS [_IconFor_DisplayName]
       -- add a link to the node's details page
     , [Nodes].DetailsUrl AS [_LinkFor_DisplayName]
FROM Orion.Nodes AS [Nodes]
WHERE [Nodes].Status = 1 -- 1 = 'Up' (See Orion.StatusInfo for a complete list)
  AND [Nodes].External = False -- (Not External)
  AND [Nodes].ObjectSubType <> 'ICMP' -- (Not ICMP)
  -- some very specific devices do not report their CPU, so we'll skip them.
  AND [Nodes].CPUCount IS NOT NULL 
-- We'll sort by Caption/DisplayName because it's convenient
ORDER BY [Nodes].DisplayName

Most element types in the SolarWinds API have a DetailsUrl property, so we can bring it in very easily.  Now our Display Names are links and (BONUS!) support hover-over functionality.

Adding _LinkFor_ to Display Name provides hover-over  functionality.

Getting Specific

These options are great for "summary" pages, but what if we wanted a custom query widget for specific pages?  Many pages include "hidden" macros which identify the entity in view.  For nodes, you can use the variable ${NodeID} in your query and when the query is executed, that Node's ID is inserted into your query.

There are too many permutations to list them all here, but if you are interested in seeing one in action, you can download and review Group Membership (Node) from the Custom Queries Content Exchange.

Remember that the _LinkFor_ and _IconFor_ Macros must exactly end with the name of the property returned. If you change "DisplayName" to "Caption Name", you must also update the _LinkFor_ and _IconFor_ macros to match.

  • LinkFor
  • Custom Query
  • IconFor
  • Macros
  • Share
  • History
  • More
  • Cancel
Related
Recommended

SolarWinds solutions are rooted in our deep connection to our user base in the THWACK® online community. More than 200,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.

SolarWinds Customer Success Center Certification SolarWinds Lab Link Customer Portal
About THWACK SolarWinds Blog Federal & Government Edit Settings Free Tools & Trials
Legal Documents Terms of Use Privacy California Privacy Rights Security Information
©2021 SolarWinds Worldwide, LLC. All Rights Reserved.