SWQL Query Assistance

I need some help with a SWQL query. Right now, I'm running a query to return a count of devcies that have 100% availability over the last 31 days with this query and this is working great:

"SELECT COUNT(*) AS [100% Available] FROM (SELECT [Nodes].Caption , AVG([Nodes].ResponseTimeHistory.Availability) AS [Availability] FROM Orion.Nodes AS [Nodes] WHERE [Nodes].NodeName LIKE '%WTNC%' AND [Nodes].ResponseTimeHistory.DateTime BETWEEN GETDATE() - 31 AND GETDATE() GROUP BY [Nodes].Caption HAVING AVG([Nodes].ResponseTimeHistory.Availability) = 100)"

But I need to create two other queries and don't know exactly how to do it in SWQL language.

The two queries I want are:

1. A query that will just look at the business day's - So Monday thru Friday from 8am to 5pm.
2. A query that will look at every day, but exclude Sunday's from Midnight to 6am (our maintenance window)

Can anyone assist with this?

Thanks.

Parents
  • I wont write these right now because I'm leaving the office shortly, but also there's definitely some examples around

    For both 1 and 2 the solution is to add and "AND ()" into your WHERE condition, and use the datetime functions here:

    • GetUtcDate() - Returns the current date and time in UTC.
    • Hour(d) - Returns the hour part of d (in 24 hour format).
    • DateTrunc('datepart', 'd') - Where 'datepart' is one of the following strings: 'minute''hour''day''week''month''quarter''year'. Returns a date like d, but with all components more granular than 'datepart' set to
    • WeekDay(d) - Returns the day of the week of d as a number, with Sunday = 0, Monday = 1, ..., Saturday = 6. Available in Orion Platform 2016.1 and later.

     

    I think the usual approach is to compare DATETRUNC(x, GETUTCDATE()) to be > StartOfWindowInX and < EndofWindowInX

    In SQL the BETWEEN function is available but not in SWQL yet as far as I'm aware, here's hoping.

Reply
  • I wont write these right now because I'm leaving the office shortly, but also there's definitely some examples around

    For both 1 and 2 the solution is to add and "AND ()" into your WHERE condition, and use the datetime functions here:

    • GetUtcDate() - Returns the current date and time in UTC.
    • Hour(d) - Returns the hour part of d (in 24 hour format).
    • DateTrunc('datepart', 'd') - Where 'datepart' is one of the following strings: 'minute''hour''day''week''month''quarter''year'. Returns a date like d, but with all components more granular than 'datepart' set to
    • WeekDay(d) - Returns the day of the week of d as a number, with Sunday = 0, Monday = 1, ..., Saturday = 6. Available in Orion Platform 2016.1 and later.

     

    I think the usual approach is to compare DATETRUNC(x, GETUTCDATE()) to be > StartOfWindowInX and < EndofWindowInX

    In SQL the BETWEEN function is available but not in SWQL yet as far as I'm aware, here's hoping.

Children