endcollector 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/endcollector.rb +25 -0
- data/lib/influx.rb +31 -0
- data/lib/jira.rb +103 -0
- data/lib/nagios.rb +40 -0
- data/lib/payload.rb +28 -0
- metadata +218 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c39537bacba711fcae7e73ce815243f485ceeed2
|
4
|
+
data.tar.gz: fd355a7dc78edadd1cb0fdd19d021456b146de6a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21bf1161a592093ba1fed7910939f23233febcb253f2ea4479dadb345d8e55435727c624dc6e1774d7f77e23416318a1a74b111e9c972c4dae221ef7dea2abf7
|
7
|
+
data.tar.gz: cc7f3412db9886eafabacbd2f503f359b7e493611862fb092eeeae2770632aca46ff247456fb114fc3e707eb3723a170b1afd57741981aca1fddb6a6beac0bf4
|
data/lib/endcollector.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'influxdb'
|
3
|
+
require 'jira-ruby'
|
4
|
+
require 'nagios_analyzer'
|
5
|
+
|
6
|
+
require 'influx'
|
7
|
+
require 'payload'
|
8
|
+
require 'jira'
|
9
|
+
require 'nagios'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
class Endcollector
|
14
|
+
|
15
|
+
attr_accessor :config
|
16
|
+
attr_accessor :jira
|
17
|
+
attr_accessor :nagios
|
18
|
+
|
19
|
+
def initialize(config_file)
|
20
|
+
@config = YAML::load_file(config_file)
|
21
|
+
@jira = Jira.new(@config)
|
22
|
+
@nagios = Nagios.new(@config)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/influx.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Influx
|
2
|
+
|
3
|
+
# Initialize InfluxDB connection class and create the database if not exists
|
4
|
+
def initialize(host, dbname, port = 8086, user = nil, pass = nil)
|
5
|
+
@host = host
|
6
|
+
@name = dbname
|
7
|
+
@port = port
|
8
|
+
@user = user
|
9
|
+
@pass = pass
|
10
|
+
@time = "s"
|
11
|
+
@connection = InfluxDB::Client.new host: @host, port: @port, username: @user, password: @pass, time_precision: @time
|
12
|
+
if @connection.list_databases.map{|r| r['name']}.compact.uniq.include? @name
|
13
|
+
@connection = InfluxDB::Client.new database: @name, host: @host, port: @port, username: @user, password: @pass, time_precision: @time
|
14
|
+
else
|
15
|
+
@connection.create_database(@name)
|
16
|
+
@connection = InfluxDB::Client.new database: @name, host: @host, port: @port, username: @user, password: @pass, time_precision: @time
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Write single datapoint to InfluxDB
|
21
|
+
def write(dataname, data)
|
22
|
+
@connection.write_point(dataname, data)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Clean measurement
|
26
|
+
def clean(measurement)
|
27
|
+
query = 'DELETE FROM ' + measurement
|
28
|
+
@connection.query query
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/jira.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
class Jira
|
2
|
+
attr_accessor :url
|
3
|
+
attr_accessor :user
|
4
|
+
attr_accessor :db
|
5
|
+
attr_accessor :all
|
6
|
+
|
7
|
+
def initialize (config)
|
8
|
+
@url = config['jira']['host']
|
9
|
+
@user = config['jira']['user']
|
10
|
+
@db = Influx.new(config['influxdb']['host'], config['jira']['dbname'], config['influxdb']['port'], config['influxdb']['user'], config['influxdb']['password'])
|
11
|
+
jira_options = {
|
12
|
+
:site => @url,
|
13
|
+
:username => @user,
|
14
|
+
:password => config['jira']['password'],
|
15
|
+
:context_path => '',
|
16
|
+
:auth_type => :basic,
|
17
|
+
:read_timeout => 60,
|
18
|
+
}
|
19
|
+
@connection = JIRA::Client.new(jira_options)
|
20
|
+
max_results_per_query = -1
|
21
|
+
issues = []
|
22
|
+
begin
|
23
|
+
issues_v = @connection.Issue.jql('', max_results: max_results_per_query, start_at: issues.size)
|
24
|
+
issues = issues + issues_v
|
25
|
+
end until issues_v.empty?
|
26
|
+
@all = issues.flatten.sort_by(&:id)
|
27
|
+
return @connection
|
28
|
+
end
|
29
|
+
|
30
|
+
def owner_list()
|
31
|
+
owners = []
|
32
|
+
self.all.each do |issue|
|
33
|
+
if issue.assignee != nil
|
34
|
+
owners << issue.assignee.displayName
|
35
|
+
end
|
36
|
+
end
|
37
|
+
owners.uniq!.sort!
|
38
|
+
end
|
39
|
+
|
40
|
+
def status_list()
|
41
|
+
status_list = []
|
42
|
+
self.all.each do |issue|
|
43
|
+
status_list << issue.status.name
|
44
|
+
end
|
45
|
+
status_list.uniq!.sort!
|
46
|
+
end
|
47
|
+
|
48
|
+
def priority_list()
|
49
|
+
priority_list = []
|
50
|
+
self.all.each do |issue|
|
51
|
+
if issue.priority != nil
|
52
|
+
priority_list << issue.priority.name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
priority_list.uniq!.sort!
|
56
|
+
end
|
57
|
+
|
58
|
+
def project_list()
|
59
|
+
project_list = []
|
60
|
+
self.all.each do |issue|
|
61
|
+
if issue.project != nil
|
62
|
+
project_list << issue.project.name
|
63
|
+
end
|
64
|
+
end
|
65
|
+
project_list.uniq!.sort!
|
66
|
+
end
|
67
|
+
|
68
|
+
def by_status(status)
|
69
|
+
issues = self.all.select{|issue| issue.status != nil}.select{|issue| issue.status.name == status}
|
70
|
+
end
|
71
|
+
|
72
|
+
def by_owner(owner)
|
73
|
+
issues = self.all.select{|issue| issue.assignee != nil}.select{|issue| issue.assignee.displayName == owner}
|
74
|
+
end
|
75
|
+
|
76
|
+
def by_priority(priority)
|
77
|
+
issues = self.all.select{|issue| issue.priority != nil}.select{|issue| issue.priority.name == priority}
|
78
|
+
end
|
79
|
+
|
80
|
+
def by_project(project)
|
81
|
+
issues = self.all.select{|issue| issue.project != nil}.select{|issue| issue.project.name == project}
|
82
|
+
end
|
83
|
+
|
84
|
+
def by_overdue()
|
85
|
+
issues = self.all.select{|issue| issue.duedate != nil}.select{|issue| Time.parse(issue.duedate) < Time.now}.select{|issue| issue.status.name != "Done"}.select{|issue| issue.status.name != "Closed"}
|
86
|
+
end
|
87
|
+
|
88
|
+
def by_owner_nid(owner)
|
89
|
+
issues = self.all.select{|issue| issue.assignee != nil}.select{|issue| issue.assignee.name == owner}
|
90
|
+
end
|
91
|
+
|
92
|
+
def by_owner_and_status(owner, status)
|
93
|
+
issues = self.all.select{|issue| issue.assignee != nil}.select{|issue| issue.assignee.displayName == owner}.select{|issue| issue.status.name == status}
|
94
|
+
end
|
95
|
+
|
96
|
+
def by_owner_and_priority(owner, priority)
|
97
|
+
issues = self.all.select{|issue| issue.assignee != nil}.select{|issue| issue.assignee.displayName == owner}.select{|issue| issue.priority.name == priority}
|
98
|
+
end
|
99
|
+
|
100
|
+
def own()
|
101
|
+
self.by_owner_nid(self.user)
|
102
|
+
end
|
103
|
+
end
|
data/lib/nagios.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Nagios
|
2
|
+
attr_accessor :db
|
3
|
+
attr_accessor :all
|
4
|
+
attr_accessor :problems
|
5
|
+
|
6
|
+
def initialize (config)
|
7
|
+
@db = Influx.new(config['influxdb']['host'], config['nagios']['dbname'], config['influxdb']['port'], config['influxdb']['user'], config['influxdb']['password'])
|
8
|
+
@status = NagiosAnalyzer::Status.new(config['nagios']['file'], include_ok: true)
|
9
|
+
@all = @status.service_items
|
10
|
+
@problems = @status.service_problems
|
11
|
+
return @status
|
12
|
+
end
|
13
|
+
|
14
|
+
def host_list()
|
15
|
+
host_list = []
|
16
|
+
self.all.each do |service|
|
17
|
+
host_list << service.host_name
|
18
|
+
end
|
19
|
+
host_list.uniq!.sort!
|
20
|
+
end
|
21
|
+
|
22
|
+
def status_list()
|
23
|
+
status_list = []
|
24
|
+
self.all.each do |service|
|
25
|
+
status_list << service.status
|
26
|
+
end
|
27
|
+
status_list.uniq!.sort!
|
28
|
+
end
|
29
|
+
|
30
|
+
def by_host(host)
|
31
|
+
issues = self.all.select{ |service| service.host_name == host}
|
32
|
+
return issues
|
33
|
+
end
|
34
|
+
|
35
|
+
def by_status(status)
|
36
|
+
issues = self.all.select{ |service| service.status == status}
|
37
|
+
return issues
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/payload.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Payload
|
2
|
+
# Payload structure:
|
3
|
+
# {values: {vname1: vdata1, vname2: vdata2}, tags: {tname1: tdata1, tname2: tdata2}, timestamp: time}
|
4
|
+
@p
|
5
|
+
|
6
|
+
def initialize()
|
7
|
+
@p = {:values => {}, :tags => {}, :timestamp => Time.now.to_i}
|
8
|
+
return @p
|
9
|
+
end
|
10
|
+
|
11
|
+
def v(vname, vdata)
|
12
|
+
@p[:values].store(vname.to_s.to_sym, vdata)
|
13
|
+
end
|
14
|
+
|
15
|
+
def t(tname, tdata)
|
16
|
+
@p[:tags].store(tname.to_s.to_sym, tdata)
|
17
|
+
end
|
18
|
+
|
19
|
+
def clean()
|
20
|
+
@p[:values] = {}
|
21
|
+
@p[:tags] = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
def p()
|
25
|
+
return @p
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: endcollector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.18
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Bannicov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.13'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.13'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.13'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '10.0'
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '10.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '10.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: jira-ruby
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.2.0
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.2.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.2.0
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.2.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: influxdb
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.3.13
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.13
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.3.13
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.3.13
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: nagios_analyzer
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.0.5
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.0.5
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.0.5
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.0.5
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: jira-ruby
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 1.2.0
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.2.0
|
123
|
+
type: :runtime
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 1.2.0
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 1.2.0
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: influxdb
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 0.3.13
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 0.3.13
|
143
|
+
type: :runtime
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 0.3.13
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.3.13
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: nagios_analyzer
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.0.5
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 0.0.5
|
163
|
+
type: :runtime
|
164
|
+
prerelease: false
|
165
|
+
version_requirements: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - "~>"
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: 0.0.5
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 0.0.5
|
173
|
+
description: |-
|
174
|
+
Nagios and JIRA stats collector >> InfluxDB.
|
175
|
+
WARNING!
|
176
|
+
This gem is in DEEP, DEEP beta. Internal use only.
|
177
|
+
email:
|
178
|
+
- igor.bannicov@gmail.com
|
179
|
+
executables: []
|
180
|
+
extensions: []
|
181
|
+
extra_rdoc_files: []
|
182
|
+
files:
|
183
|
+
- lib/endcollector.rb
|
184
|
+
- lib/influx.rb
|
185
|
+
- lib/jira.rb
|
186
|
+
- lib/nagios.rb
|
187
|
+
- lib/payload.rb
|
188
|
+
homepage: http://www.bannicov.com/endcollector.html
|
189
|
+
licenses:
|
190
|
+
- MIT
|
191
|
+
metadata:
|
192
|
+
allowed_push_host: https://rubygems.org
|
193
|
+
post_install_message: |2
|
194
|
+
|
195
|
+
############################################
|
196
|
+
WARNING!!!
|
197
|
+
Deep, deep beta! Provided AS-IS!
|
198
|
+
############################################
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: 2.0.0
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
requirements: []
|
213
|
+
rubyforge_project:
|
214
|
+
rubygems_version: 2.5.2
|
215
|
+
signing_key:
|
216
|
+
specification_version: 4
|
217
|
+
summary: Nagios and JIRA stats collector >> InfluxDB
|
218
|
+
test_files: []
|