cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Host List without Management Zone

gbaudart
DynaMight Champion
DynaMight Champion

Hi Community,


I'd like to output a list of Hosts that are not in a ManagementZone.
The EntitySelector does not allow us to do this.


Do you have an idea?

Observability Consultant - Dynatrace Professional Certified
12 REPLIES 12

AntonPineiro
DynaMight Guru
DynaMight Guru

Hi,

I would say using entities API:

  1. Call entities API to get a full host list.
  2. Call entity API per host ID in before query.

Second one is providing much more information than mz, but you can see if that host has a MZ or not:

AntonPineiro_0-1706003113199.png

Best regards

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

Isn't there an easier way to get the information?

Observability Consultant - Dynatrace Professional Certified

This may help, part of a dashboard - not my code, from a DT SME.

import { monitoredEntitiesClient } from '@dynatrace-sdk/client-classic-environment-v2';

export default async function() {
  // Check if that tile should be activated based on selected indicators and scope
  if($Indicators[0] === "All" || $Indicators.includes("hostGroupCoverage")) {
    let scope;
    if($Scope[0] === "Tenant") {
      scope = 'Tenant';
    } else {
      let mzList = "";
      for(let i=0; i<$Scope.length; i++) {
        mzList += i === 0 ? `"${$Scope[i]}"` : `,"${$Scope[i]}"`;
      }
      scope = mzList;
    }
    // Define entity selector based on the selected scope
    let entitySelector;
    if(scope === "Tenant") {
      entitySelector = 'type("HOST"),isMonitoringCandidate(false)';
    } else {
      entitySelector = `type("HOST"),isMonitoringCandidate(false),mzName(${scope})`;
    }
    let config = { from: `now-1d`, entitySelector: entitySelector};
    // Get all monitored hosts
    const monitoredHosts = await monitoredEntitiesClient.getEntities(config);
    // Define entity selector based on the selected scope
    if(scope === "Tenant") {
      entitySelector = 'type("HOST"),isMonitoringCandidate(false),fromRelationships.isInstanceOf(type("HOST_GROUP"))';
    } else {
      entitySelector = `type("HOST"),isMonitoringCandidate(false),fromRelationships.isInstanceOf(type("HOST_GROUP")),mzName(${scope})`;
    }
    config = { from: `now-1d`, entitySelector: entitySelector};
    // Get all monitored hosts that are assigned with a host group
    const hostsWithHostGroup = await monitoredEntitiesClient.getEntities(config);
    // Compute host group coverage
    const hostGroupCoverage = parseInt(hostsWithHostGroup.totalCount/monitoredHosts.totalCount*100);
    // Compute local score based on the host group coverage
    const score = hostGroupCoverage === 100 ? 1 : (hostGroupCoverage >= 80 ? 0.5 : 0);
    let result;
    switch(true) {
      case score === 1:
        result = ` ${hostGroupCoverage}%`;
        break;
      case score === 0.5:
        result = `💡 ${hostGroupCoverage}%`;
        break;
      case score === 0:
        result = `⚠️ ${hostGroupCoverage}%`;
        break;
    }
    // Return the emojied result
    return result;
  } else {
    return "N/A";
  }
}

 

gbaudart
DynaMight Champion
DynaMight Champion

hi @PraWij

Thanks for this code.

OK, but what are the $Indicators and $Scope variables?

Observability Consultant - Dynatrace Professional Certified

PraWij_0-1706203177210.png

 

In the full dashboard, scope also includes the mgmt zones. 

Indicators example:

PraWij_1-1706203301677.png

 

Hi,

Maybe easier can be using Grail, if it is enabled in your tenant. I think you know more Grail than mine but something as that:

 

fetch dt.entity.host 
|  expand managementZones
|  filter managementZones == ""

 

Best regards

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

@AntonPineiro 
This doesn't work. I'll try with the sdk

Observability Consultant - Dynatrace Professional Certified

Hi,

You can try this one, looks like is working:

fetch dt.entity.host
| fieldsAdd managementZones
| filter isNull(managementZones)

AntonPineiro_0-1706377351198.png

Best regards

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

@AntonPineiro This works for me. Thanks a lot.

Tijust

Dynatrace Professional Certified

You are welcome!

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

MarwanC
Guide

This looks interesting,

fetch dt.entity.host
| fieldsAdd managementZones
| filter isNull(managementZones)

What do I need to add to search by a particular management zone?  contains or equal? need the DQL.

Hi,

Maybe more than one option but looks like this:

fetch dt.entity.host
| fieldsAdd managementZones
| filter matchesValue(managementZones, "XXXXXX")

Best regards

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

Featured Posts