Module: Legion::Extensions::ServiceNow::CmdbHealth::Runners::CmdbHealth

Includes:
Helpers::Lex, Helpers::Client
Included in:
Legion::Extensions::ServiceNow::Client
Defined in:
lib/legion/extensions/service_now/cmdb_health/runners/cmdb_health.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #fetch_oauth2_token, #handle_response

Instance Method Details

#get_cmdb_health_dashboardObject



17
18
19
20
# File 'lib/legion/extensions/service_now/cmdb_health/runners/cmdb_health.rb', line 17

def get_cmdb_health_dashboard(**)
  resp = connection(**).get('/api/now/cmdb/health_dashboard')
  { dashboard: resp.body['result'] }
end

#list_duplicate_cis(class_name:, sysparm_limit: 100) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/legion/extensions/service_now/cmdb_health/runners/cmdb_health.rb', line 22

def list_duplicate_cis(class_name:, sysparm_limit: 100, **)
  params = {
    sysparm_query: "sys_class_name=#{class_name}",
    sysparm_limit: sysparm_limit
  }
  resp = connection(**).get('/api/now/table/cmdb_duplicate', params)
  { duplicates: resp.body['result'] }
end

#list_health_rules(sysparm_limit: 100, sysparm_offset: 0) ⇒ Object



11
12
13
14
15
# File 'lib/legion/extensions/service_now/cmdb_health/runners/cmdb_health.rb', line 11

def list_health_rules(sysparm_limit: 100, sysparm_offset: 0, **)
  params = { sysparm_limit: sysparm_limit, sysparm_offset: sysparm_offset }
  resp = connection(**).get('/api/now/table/sa_m2m_suggested_relationship', params)
  { health_rules: resp.body['result'] }
end

#list_stale_cis(class_name:, days_since_discovery: 30) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/legion/extensions/service_now/cmdb_health/runners/cmdb_health.rb', line 31

def list_stale_cis(class_name:, days_since_discovery: 30, **)
  cutoff = (::Time.now - (days_since_discovery * 86_400)).strftime('%Y-%m-%d %H:%M:%S')
  params = {
    sysparm_query: "sys_class_name=#{class_name}^last_discovered<#{cutoff}",
    sysparm_limit: 100
  }
  resp = connection(**).get('/api/now/table/cmdb_ci', params)
  { stale_cis: resp.body['result'] }
end