zabbirc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/zabbirc +32 -0
- data/bin/zabbirc-install +16 -0
- data/config/config.rb +5 -0
- data/lib/zabbirc/configuration.rb +43 -0
- data/lib/zabbirc/irc/plugin.rb +20 -0
- data/lib/zabbirc/irc/plugin_methods.rb +208 -0
- data/lib/zabbirc/logger.rb +45 -0
- data/lib/zabbirc/op.rb +67 -0
- data/lib/zabbirc/op_list.rb +47 -0
- data/lib/zabbirc/priority.rb +38 -0
- data/lib/zabbirc/service.rb +86 -0
- data/lib/zabbirc/services/base.rb +56 -0
- data/lib/zabbirc/services/events.rb +31 -0
- data/lib/zabbirc/services/ops.rb +38 -0
- data/lib/zabbirc/setting.rb +31 -0
- data/lib/zabbirc/stop_error.rb +3 -0
- data/lib/zabbirc/zabbix/connection.rb +26 -0
- data/lib/zabbirc/zabbix/event.rb +94 -0
- data/lib/zabbirc/zabbix/host.rb +6 -0
- data/lib/zabbirc/zabbix/resource/associations.rb +30 -0
- data/lib/zabbirc/zabbix/resource/base.rb +52 -0
- data/lib/zabbirc/zabbix/resource/finders.rb +37 -0
- data/lib/zabbirc/zabbix/trigger.rb +47 -0
- data/lib/zabbirc/zabbix/user.rb +10 -0
- data/lib/zabbirc.rb +24 -0
- data/spec/bot_spec.rb +186 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/support/mock_bot.rb +29 -0
- data/templates/zabbirc_config.rb +14 -0
- data/thread_test.rb +46 -0
- data/tmp/playground.rb +37 -0
- metadata +171 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'cinch/test'
|
2
|
+
require 'zabbirc'
|
3
|
+
|
4
|
+
spec_dir = File.dirname(__FILE__)
|
5
|
+
Dir[File.expand_path('support/**/*.rb', spec_dir)].each do |f|
|
6
|
+
require f
|
7
|
+
end
|
8
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
9
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
10
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
11
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
12
|
+
#
|
13
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
14
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
15
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
16
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
17
|
+
# a separate helper file that requires the additional dependencies and performs
|
18
|
+
# the additional setup, and require it from the spec files that actually need it.
|
19
|
+
#
|
20
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
21
|
+
# users commonly want.
|
22
|
+
#
|
23
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
24
|
+
RSpec.configure do |config|
|
25
|
+
# rspec-expectations config goes here. You can use an alternate
|
26
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
27
|
+
# assertions if you prefer.
|
28
|
+
config.expect_with :rspec do |expectations|
|
29
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
30
|
+
# and `failure_message` of custom matchers include text for helper methods
|
31
|
+
# defined using `chain`, e.g.:
|
32
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
33
|
+
# # => "be bigger than 2 and smaller than 4"
|
34
|
+
# ...rather than:
|
35
|
+
# # => "be bigger than 2"
|
36
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
37
|
+
end
|
38
|
+
|
39
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
40
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
41
|
+
config.mock_with :rspec do |mocks|
|
42
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
43
|
+
# a real object. This is generally recommended, and will default to
|
44
|
+
# `true` in RSpec 4.
|
45
|
+
mocks.verify_partial_doubles = true
|
46
|
+
end
|
47
|
+
|
48
|
+
# The settings below are suggested to provide a good initial experience
|
49
|
+
# with RSpec, but feel free to customize to your heart's content.
|
50
|
+
=begin
|
51
|
+
# These two settings work together to allow you to limit a spec run
|
52
|
+
# to individual examples or groups you care about by tagging them with
|
53
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
54
|
+
# get run.
|
55
|
+
config.filter_run :focus
|
56
|
+
config.run_all_when_everything_filtered = true
|
57
|
+
|
58
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
59
|
+
# For more details, see:
|
60
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
61
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
63
|
+
config.disable_monkey_patching!
|
64
|
+
|
65
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
66
|
+
# be too noisy due to issues in dependencies.
|
67
|
+
config.warnings = true
|
68
|
+
|
69
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# file, and it's useful to allow more verbose output when running an
|
71
|
+
# individual spec file.
|
72
|
+
if config.files_to_run.one?
|
73
|
+
# Use the documentation formatter for detailed output,
|
74
|
+
# unless a formatter has already been configured
|
75
|
+
# (e.g. via a command-line flag).
|
76
|
+
config.default_formatter = 'doc'
|
77
|
+
end
|
78
|
+
|
79
|
+
# Print the 10 slowest examples and example groups at the
|
80
|
+
# end of the spec run, to help surface which specs are running
|
81
|
+
# particularly slow.
|
82
|
+
config.profile_examples = 10
|
83
|
+
|
84
|
+
# Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# the seed, which is printed after each run.
|
87
|
+
# --seed 1234
|
88
|
+
config.order = :random
|
89
|
+
|
90
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# test failures related to randomization by passing the same `--seed` value
|
93
|
+
# as the one that triggered the failure.
|
94
|
+
Kernel.srand config.seed
|
95
|
+
=end
|
96
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Zabbirc
|
2
|
+
class MockBot
|
3
|
+
include Zabbirc::Irc::PluginMethods
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@ops = OpList.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def ops
|
10
|
+
@ops
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_nick obj
|
14
|
+
return obj if obj.is_a? String
|
15
|
+
return obj.nick if obj.respond_to? :nick
|
16
|
+
return get_nick(obj.user) if obj.respond_to? :user
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_op name, settings=nil
|
20
|
+
@@op_ids ||= 0
|
21
|
+
zabbix_user = Zabbix::User.new(alias: name, userid: (@@op_ids+=1))
|
22
|
+
op = Op.new(zabbix_user: zabbix_user, irc_user: Object.new)
|
23
|
+
settings.each do |key, value|
|
24
|
+
op.setting.set key, value
|
25
|
+
end if settings
|
26
|
+
@ops.add op
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Zabbirc.configure do |config|
|
2
|
+
### Zabbix server configuration
|
3
|
+
config.zabbix_api_url = "https://your.zabbix-server.com/zabbix/api_jsonrpc.php"
|
4
|
+
config.zabbix_login = "zabbirc"
|
5
|
+
config.zabbix_password = "zabbircpass"
|
6
|
+
|
7
|
+
### IRC configurations
|
8
|
+
# config.irc_server = "irc.freenode.org"
|
9
|
+
# config.irc_channels = ["#zabbirc-test", "#zabbirc-test-2"]
|
10
|
+
|
11
|
+
### Zabbirc configurations
|
12
|
+
# config.events_check_interval = 10.seconds
|
13
|
+
# config.notify_about_events_from_last = 5.minutes
|
14
|
+
end
|
data/thread_test.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'pry'
|
2
|
+
StopError = Object.new
|
3
|
+
$f = File.open("thread.log", "w")
|
4
|
+
|
5
|
+
def lg msg
|
6
|
+
$f.puts msg
|
7
|
+
$f.flush
|
8
|
+
end
|
9
|
+
main_thread = Thread.current
|
10
|
+
|
11
|
+
def make_thread
|
12
|
+
Thread.new do
|
13
|
+
begin
|
14
|
+
loop do
|
15
|
+
Thread.handle_interrupt(StopError => :never) do
|
16
|
+
lg "Start - critical"
|
17
|
+
sleep 5
|
18
|
+
lg "Stop - critical"
|
19
|
+
|
20
|
+
Thread.handle_interrupt(StopError => :immediate) do
|
21
|
+
lg "Start - interruptibly"
|
22
|
+
sleep 10
|
23
|
+
lg "Stop - interruptibly"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rescue => e
|
28
|
+
puts "Chyba: #{e}"
|
29
|
+
main_thread.raise e
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def start
|
35
|
+
$t = make_thread
|
36
|
+
end
|
37
|
+
|
38
|
+
def stop
|
39
|
+
$t.raise StopError
|
40
|
+
end
|
41
|
+
|
42
|
+
def q
|
43
|
+
$t.raise StandardError
|
44
|
+
end
|
45
|
+
|
46
|
+
binding.pry
|
data/tmp/playground.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
/usr/local/rvm/gems/ruby-2.1.2@zabbirc-test/bin
|
2
|
+
/usr/local/rvm/gems/ruby-2.1.2@global/bin
|
3
|
+
/usr/local/rvm/rubies/ruby-2.1.2/bin
|
4
|
+
/usr/local/rvm/bin
|
5
|
+
/usr/local/heroku/bin
|
6
|
+
/usr/local/bin
|
7
|
+
/usr/local/sbin
|
8
|
+
~/bin
|
9
|
+
/usr/bin
|
10
|
+
/bin
|
11
|
+
/usr/sbin
|
12
|
+
/sbin
|
13
|
+
/usr/local/bin
|
14
|
+
/opt/X11/bin
|
15
|
+
/Applications/Server.app/Contents/ServerRoot/usr/bin
|
16
|
+
/Applications/Server.app/Contents/ServerRoot/usr/sbin
|
17
|
+
/usr/texbin
|
18
|
+
/usr/local/bin
|
19
|
+
/usr/bin
|
20
|
+
/bin
|
21
|
+
/usr/sbin
|
22
|
+
/sbin
|
23
|
+
/usr/local/bin
|
24
|
+
/opt/X11/bin
|
25
|
+
/Applications/Server.app/Contents/ServerRoot/usr/bin
|
26
|
+
/Applications/Server.app/Contents/ServerRoot/usr/sbin
|
27
|
+
/Users/wayneeseguin/.sm/bin
|
28
|
+
/Users/wayneeseguin/.sm/pkg/active/bin
|
29
|
+
/Users/wayneeseguin/.sm/pkg/active/sbin
|
30
|
+
/usr/local/mysql/bin
|
31
|
+
/usr/bin
|
32
|
+
/usr/local/bin
|
33
|
+
/Users/tulak/Documents/Android Development/android-sdk-macosx/tools
|
34
|
+
/Users/tulak/Documents/Android Development/android-sdk-macosx/platform-tools
|
35
|
+
/Users/tulak/.rvm/bin
|
36
|
+
/usr/local/sbin
|
37
|
+
/usr/local/gnat/bin
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zabbirc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Filip Zachar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.6
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.1.6
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.1.6
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.1.6
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dotenv
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.0.2
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: cinch
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.1'
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.1'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: zabbix-client
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0.1'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.1.0
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.1'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 0.1.0
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: pry
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0.10'
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.0
|
97
|
+
type: :runtime
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 0.10.0
|
107
|
+
description: IRC Bot for Zabbix monitoring
|
108
|
+
email: tulak45@gmail.com
|
109
|
+
executables:
|
110
|
+
- zabbirc
|
111
|
+
- zabbirc-install
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- bin/zabbirc
|
116
|
+
- bin/zabbirc-install
|
117
|
+
- config/config.rb
|
118
|
+
- lib/zabbirc.rb
|
119
|
+
- lib/zabbirc/configuration.rb
|
120
|
+
- lib/zabbirc/irc/plugin.rb
|
121
|
+
- lib/zabbirc/irc/plugin_methods.rb
|
122
|
+
- lib/zabbirc/logger.rb
|
123
|
+
- lib/zabbirc/op.rb
|
124
|
+
- lib/zabbirc/op_list.rb
|
125
|
+
- lib/zabbirc/priority.rb
|
126
|
+
- lib/zabbirc/service.rb
|
127
|
+
- lib/zabbirc/services/base.rb
|
128
|
+
- lib/zabbirc/services/events.rb
|
129
|
+
- lib/zabbirc/services/ops.rb
|
130
|
+
- lib/zabbirc/setting.rb
|
131
|
+
- lib/zabbirc/stop_error.rb
|
132
|
+
- lib/zabbirc/zabbix/connection.rb
|
133
|
+
- lib/zabbirc/zabbix/event.rb
|
134
|
+
- lib/zabbirc/zabbix/host.rb
|
135
|
+
- lib/zabbirc/zabbix/resource/associations.rb
|
136
|
+
- lib/zabbirc/zabbix/resource/base.rb
|
137
|
+
- lib/zabbirc/zabbix/resource/finders.rb
|
138
|
+
- lib/zabbirc/zabbix/trigger.rb
|
139
|
+
- lib/zabbirc/zabbix/user.rb
|
140
|
+
- spec/bot_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/support/mock_bot.rb
|
143
|
+
- templates/zabbirc_config.rb
|
144
|
+
- thread_test.rb
|
145
|
+
- tmp/playground.rb
|
146
|
+
homepage: http://rubygems.org/gems/zabbirc
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.2.2
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: IRC Bot for Zabbix monitoring
|
170
|
+
test_files: []
|
171
|
+
has_rdoc:
|