Class: WatchtowerJob::WorkflowCounts

Inherits:
Object
  • Object
show all
Defined in:
lib/watchtower_job/workflow_counts.rb

Constant Summary collapse

WORKFLOWS =

these are the only ones to monitor

%w(GETSEND FTPPROC SHERLOCK SHERLOCK_FILE)

Instance Method Summary collapse

Constructor Details

#initializeWorkflowCounts

Returns a new instance of WorkflowCounts.



4
5
6
7
# File 'lib/watchtower_job/workflow_counts.rb', line 4

def initialize
  @workflows = Hash.new
  reset_workflows_hash
end

Instance Method Details

#count(workflow_type) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/watchtower_job/workflow_counts.rb', line 9

def count(workflow_type)
  unless WORKFLOWS.include?(workflow_type)
    WatchtowerJob.log.warn("#{workflow_type} is unsupported workflow type!") unless WORKFLOWS.include?(workflow_type)
    return nil
  end
  @workflows[lookup_ci_name(workflow_type)] += 1
end

#lookup_ci_name(workflow) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/watchtower_job/workflow_counts.rb', line 31

def lookup_ci_name(workflow)
  name =
    case workflow
    when 'GETSEND'
      'NT2.GetsendWorkflow'
    when 'FTPPROC'
      'NT2.FTPProcWorkflow'
    when 'SHERLOCK', 'SHERLOCK_FILE'
      'NT2.SherlockWorkflow'
    else
      return nil
    end
  return "PREP.#{name}" if WatchtowerJob.nt2_env == 'prep'
  name
end

#send_countsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/watchtower_job/workflow_counts.rb', line 17

def send_counts
  @workflows.each do |config_item_name, count|
    WatchtowerJob.einstein_event_collector.post_event(
      WatchtowerJob.einstein_event_collector.event_body(
        config_item_type: 'Service',
        config_item_name: config_item_name,
        event_type: 'successful runs',
        value: count
      )
    )
  end
  reset_workflows_hash
end