svarog-client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/svarog-client +9 -0
- data/lib/svarog-client.rb +4 -0
- data/lib/svarog/client.rb +62 -0
- data/lib/svarog/parser.rb +53 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 485500c41a0bebbf64266b5a745d277847f48a58
|
4
|
+
data.tar.gz: 7b0f2eecc108c14be4dd9c6c76950f9212cdd9dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ceb78d36ae1e1029326d49a2d5e080b7a31289159b45a97b8cf0d8a45e7a6011e97e96ec12153587c3ab947c098181b0d69fb02c7d28f811480927e6be2552c
|
7
|
+
data.tar.gz: 4bc73e721f73b62936d48e6af456253691420137b5861aeab46095e301b28323d9803c978d879f0ffbaf22f63fcf77b210e8442f7651e8d11e531e7aa5d708bf
|
data/bin/svarog-client
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
require 'uri'
|
5
|
+
require 'socket'
|
6
|
+
|
7
|
+
|
8
|
+
module Svarog
|
9
|
+
class Client
|
10
|
+
|
11
|
+
@@attributes = [:server, :username, :password]
|
12
|
+
attr_accessor *@@attributes
|
13
|
+
|
14
|
+
def initialize(args = {})
|
15
|
+
if args.empty?
|
16
|
+
config_file = File.expand_path("~/.svarog.yml")
|
17
|
+
|
18
|
+
if File.exist? config_file
|
19
|
+
config = YAML.load_file(config_file)
|
20
|
+
@server = config["svarog-server"]["url"]
|
21
|
+
@username = config["svarog-server"]["username"]
|
22
|
+
@password = config["svarog-server"]["password"]
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Missing required arguments"
|
25
|
+
end
|
26
|
+
else
|
27
|
+
args.keys.each do |k|
|
28
|
+
key = k.to_sym
|
29
|
+
instance_variable_set("@#{key}", args[key]) if @@attributes.include?(key)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def notify(message, sender=nil, type=nil)
|
35
|
+
begin
|
36
|
+
svarog_server_url = self.construct_url
|
37
|
+
|
38
|
+
notification = Hash.new
|
39
|
+
notification[:sender] = sender || Socket.gethostname
|
40
|
+
notification[:text] = message
|
41
|
+
notification[:type] = type || 'alert'
|
42
|
+
|
43
|
+
request = RestClient.post(svarog_server_url, notification)
|
44
|
+
request.code == 200
|
45
|
+
rescue Errno::ECONNREFUSED => e
|
46
|
+
puts "\033[33mERROR: Svarog server is not running, please start svarog server\033[0m"
|
47
|
+
puts "#{svarog_server_url} => #{e.message}"
|
48
|
+
exit 1
|
49
|
+
rescue URI::InvalidURIError, RestClient::ResourceNotFound => e
|
50
|
+
puts "\033[33mERROR: The configuration is incorrect, please review the configuration file for possible errors\033[0m"
|
51
|
+
puts "\033[33mSvarog server: #{e.message}\033[0m"
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def construct_url
|
57
|
+
uri = URI(self.server)
|
58
|
+
"#{uri.scheme}://#{self.username}:#{self.password}@#{uri.host}:#{uri.port}#{uri.path}"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'choice'
|
2
|
+
|
3
|
+
module Svarog
|
4
|
+
class Parser
|
5
|
+
def self.parse(args)
|
6
|
+
Choice.options do
|
7
|
+
header 'Application options:'
|
8
|
+
|
9
|
+
separator 'Required:'
|
10
|
+
|
11
|
+
option :message, :required => true do
|
12
|
+
short '-m'
|
13
|
+
long '--message=MESSAGE'
|
14
|
+
desc 'The notification message'
|
15
|
+
end
|
16
|
+
|
17
|
+
separator 'Optional:'
|
18
|
+
option :sender do
|
19
|
+
short '-s'
|
20
|
+
long '--sender=SENDER'
|
21
|
+
desc 'The notification sender (e.g. hostname)'
|
22
|
+
end
|
23
|
+
|
24
|
+
option :type do
|
25
|
+
short '-t'
|
26
|
+
long '--type=Type'
|
27
|
+
desc 'The notification type (e.g. info, alert, success, warning)'
|
28
|
+
default 'alert'
|
29
|
+
end
|
30
|
+
|
31
|
+
separator 'Common:'
|
32
|
+
|
33
|
+
option :help do
|
34
|
+
short '-h'
|
35
|
+
long '--help'
|
36
|
+
desc 'Show this message.'
|
37
|
+
end
|
38
|
+
|
39
|
+
option :version do
|
40
|
+
short '-v'
|
41
|
+
long '--version'
|
42
|
+
desc 'Show version.'
|
43
|
+
action do
|
44
|
+
puts 'Command line tool for Svarog server'
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Choice.choices
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: svarog-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladislav Lewin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: choice
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This gem provides a very simple command line tool to send notifications
|
42
|
+
to the Svarog server
|
43
|
+
email: vlewin[at]suse.de
|
44
|
+
executables:
|
45
|
+
- svarog-client
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- lib/svarog/client.rb
|
50
|
+
- lib/svarog/parser.rb
|
51
|
+
- lib/svarog-client.rb
|
52
|
+
- bin/svarog-client
|
53
|
+
homepage: https://github.com/vlewin/svarog-client
|
54
|
+
licenses: []
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.1.11
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Svarog Client
|
76
|
+
test_files: []
|
77
|
+
has_rdoc:
|