View - script API
StackState Self-hosted v4.6.x

Function getAll

Returns a list of all views.
Args:
None
Return type:
AsyncScriptResult[List[QueryViewResponse]]
Fields:
  • QueryViewResponse.view - the QueryView object
  • QueryViewResponse.viewInfo - (optional) ViewInfo structure holding extra information that can be requested using builder methods
The QueryView type has the following fields:
  • QueryView.name - the name of the view
  • QueryView.description - the description of the view
  • QueryView.state - View state object, holding view state
  • QueryView.query - STQL query which can be used subsequently in getting topology using Topology Script Api​
The ViewInfo type has the following fields:
  • ViewInfo.stars.count - the number of times a star was given by any user to the view
Builder methods
withStarCount - adds the number of times a star was given by any user to the view info of each view.
If this flag is set the query response will contain the viewInfo holding star count. The stars count is available on this path viewResponse.viewInfo.stars.count
Examples:
The following example collects the names of all components in all views.
1
View.getAll()
2
.thenInject([]) { componentNames, view ->
3
Topology.query(view.view.query)
4
.components()
5
.then {
6
components -> componentNames + components.collect { it.name }
7
}
8
}
9
.then {
10
it.unique()
11
}
Copied!

Function: withId(viewId).problems()

Returns a list of all problems in a view.

Args

  • viewId - the ID of the view to query for problems.

Return type

AsyncScriptResult[List[ProblemWithDetails]]

Fields

  • contributingProblems - list of all contributing problems with details:
    • contributingProblems.causeId - the ID of the topology element contributing to this problem.
    • contributingProblems.causeName - the name of the topology element contributing to this problem.
    • contributingProblems.causeType - the type of the topology element contributing to this problem.
    • contributingProblems.failingCheckNames - the names of the checks that are failing at the moment of fetching this problem contributor.
    • contributingProblems.healthState - the current health state of the contributor, either deviating or critical.
    • contributingProblems.propagatedHealthState - the propagated health state of the contributor, either deviating or critical.
  • problemId - the ID of the problem
  • rootCause - the root cause component for the queried problem:
    • rootCause.causeId - the ID of the root cause topology component, the bottom-most component in the problem cluster.
    • rootCause.causeName - the name of the root cause topology component.
    • rootCause.causeType - the type of the root cause component.
    • rootCause.failingCheckNames - the names of the checks that are failing at the moment of fetching the root cause component .
    • rootCause.healthState - the current health state of the root cause component, either deviating or critical.
    • rootCause.propagatedHealthState - the propagated health state of the root cause component, either deviating or critical.
  • viewId - the ID of the queried view.

Builder methods

None.

Examples

The example below returns the name of the root cause component of the first problem in the view 230470072729670, together with the names of any failing checks on that component
1
View
2
.withId(230470072729670)
3
.problems()
4
.then{ problems ->
5
problems.isEmpty()? null :
6
problems[0].rootCause.causeName + " - failed check(s): " +
7
problems[0].rootCause.failingCheckNames
8
}
Copied!

Function: 'withId(viewId).problem(problemId)'

Args

  • viewId - the ID of the view containing the problem.
  • problemId - the ID of a problem to return details for.

Return type

AsyncScriptResult[ProblemWithDetails]

Fields

  • contributingProblems - list of all contributing problems with details:
    • contributingProblems.causeId
    • contributingProblems.causeName
    • contributingProblems.causeType
    • contributingProblems.failingCheckNames
    • contributingProblems.healthState
    • contributingProblems.propagatedHealthState
  • problemId - the ID of the problem
  • rootCause - the root cause component for the queried problem:
    • rootCause.causeId
    • rootCause.causeName
    • rootCause.causeType
    • rootCause.failingCheckNames
    • rootCause.healthState
    • rootCause.propagatedHealthState
  • viewId - the ID of the queried view.

Builder methods

None.

Examples

The example below returns the names of all checks failing for the problem with ID 65706558771339 in the view with ID 105520781477197
1
View
2
.withId(105520781477197)
3
.problem(65706558771339)
4
.then{ problem ->
5
problem.contributingProblems.failingCheckNames.unique()
6
}
Copied!
In an event handler, we can get the view ID and problem ID automatically from the configuration of the event handler function:
1
View
2
.withId(view)
3
.problem(event.problemId)
4
.then { problem ->
5
problem.contributingProblems.failingCheckNames.unique()
6
}
Copied!