qnotifier 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -4,10 +4,9 @@ bin/qnotifier
4
4
  config/qnotifier_config.yml
5
5
  config/README
6
6
  gem-public_cert.pem
7
- lib/command.rb
8
7
  lib/plugin.rb
9
8
  lib/qnotifier.rb
10
- lib/qnotifierd.rb
9
+ lib/qnotifier_runner.rb
11
10
  lib/storage.rb
12
11
  lib/web_service.rb
13
12
  plugins/apache.rb
data/bin/qnotifier CHANGED
@@ -1,5 +1,217 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift( File.join( File.dirname(__FILE__), '../lib' ) )
3
- require "command"
4
- Qnotifier::Command.run(ARGV)
3
+ require 'fileutils'
5
4
 
5
+ module Qnotifier
6
+ class Command
7
+
8
+ def self.run(argv)
9
+
10
+ unless Process.euid == 0
11
+ puts "QNotifier should be only started by root (the daemon will drop privs)"
12
+ exit
13
+ end
14
+
15
+ if has_api_key?
16
+ if argv.first == 'stop'
17
+ stop
18
+
19
+ elsif argv.first == 'start'
20
+ start
21
+
22
+ elsif argv.first == 'restart'
23
+ stop
24
+ start
25
+
26
+ elsif argv.first == 'zap'
27
+ zap
28
+
29
+ elsif argv.first == 'reset'
30
+ print "\nWould you like to reset the state of the saved variables? (y/n):"
31
+ response = STDIN.gets.chomp.downcase!
32
+ if response == "y" || response == "yes"
33
+ `rm /var/lib/qnotifier/saved_variables.yml`
34
+ end
35
+
36
+ elsif argv.first == 'register'
37
+ require "qnotifier"
38
+ qnotifier = Qnotifier::MainProcess.new
39
+ qnotifier.wipe
40
+ setup_registration
41
+
42
+ elsif argv.first == 'debug'
43
+ puts "Running once in debug mode (use this mode to debug your plugins)\n\n"
44
+ require "qnotifier"
45
+ qnotifier = Qnotifier::MainProcess.new
46
+ $qnotifier_debug = true
47
+ qnotifier.run
48
+
49
+ elsif argv.first == 'setup-directories'
50
+ setup_directories
51
+
52
+ else
53
+ puts "usage: qnotifier start | stop | restart | zap | reset | register | debug"
54
+ puts "see http://qnotifier.com for more details"
55
+ end
56
+
57
+ else
58
+ puts "No API Key Found"
59
+ setup_directories
60
+ setup_registration
61
+ end
62
+ end
63
+
64
+ def self.has_api_key?
65
+ api_key = nil
66
+ begin
67
+ api_key_file = File.open("/var/lib/qnotifier/api_key")
68
+ while (line = api_key_file.readline)
69
+ api_key = line
70
+ end
71
+ rescue EOFError
72
+ rescue Exception => e
73
+ end
74
+ if api_key
75
+ return true
76
+ else
77
+ if File.exists?("/var/lib/qnotifier/api_key")
78
+ puts "API Key file exists but cannot read API Key, exiting"
79
+ exit
80
+ end
81
+ return false
82
+ end
83
+ end
84
+
85
+ def self.setup_directories
86
+ puts "Setting Up Directories"
87
+ var_dir = "/var/lib/qnotifier"
88
+ unless File.exists?(var_dir)
89
+ begin
90
+ puts "Creating #{var_dir}"
91
+ FileUtils.mkdir_p var_dir
92
+ FileUtils.mkdir_p "#{var_dir}/plugins"
93
+ default_config_file = File.dirname(__FILE__) + "/../config/qnotifier_config.yml"
94
+ `cp #{default_config_file} #{var_dir}/qnotifier_config.yml`
95
+ readme_file = File.dirname(__FILE__) + "/../config/README"
96
+ `cp #{readme_file} #{var_dir}/plugins/README`
97
+ rescue Exception => e
98
+ puts "Can't setup the var directory: #{e}"
99
+ puts "Exiting"
100
+ exit
101
+ end
102
+ end
103
+ end
104
+
105
+ def self.setup_registration
106
+ puts "Starting QNotifier Agent Setup\n\n"
107
+ puts "In order to use this agent you must enter the six number Registration Code that was presented to you when the server was created in the QNotifier system (in the iPhone/iPad/Website).\n\n"
108
+ print "Registration Code: "
109
+ register_code = STDIN.gets.chomp
110
+
111
+ if register_code and register_code.size == 6
112
+ require "qnotifier"
113
+ qnotifier = Qnotifier::MainProcess.new
114
+ if qnotifier.register(register_code)
115
+ puts "\nOK, the server has been successfully registered."
116
+ puts "You now can control the agent as a daemon using 'qnotifier start|stop|restart'"
117
+ copy_init
118
+ puts "Doing initial update..."
119
+ qnotifier.run
120
+ puts "\nPlease start the qnotifier daemon now ('sudo qnotifier start')"
121
+ else
122
+ puts "Exiting."
123
+ end
124
+ else
125
+ puts "\nInvalid code, please enter a six number Registration Code to use this agent.\n"
126
+ exit
127
+ end
128
+ end
129
+
130
+ def self.copy_init
131
+ print "\nWould you like to install the qnotifier init script in /etc/init.d? (y/n):"
132
+ response = STDIN.gets.chomp.downcase!
133
+ if response == "y" || response == "yes"
134
+ init_file = File.dirname(__FILE__) + "/../init/qnotifier"
135
+ `cp #{init_file} /etc/init.d/`
136
+ end
137
+ end
138
+
139
+ def self.running
140
+ pid_file = "/var/lib/qnotifier/qnotifer.pid"
141
+ if File.exists?(pid_file)
142
+ begin
143
+ pid = `cat #{pid_file}`.to_i
144
+ Process.getpgid(pid)
145
+ return true
146
+ rescue
147
+ `rm #{pid_file}`
148
+ return false
149
+ end
150
+ else
151
+ return false
152
+ end
153
+ end
154
+
155
+ def self.zap
156
+ pid_file = "/var/lib/qnotifier/qnotifer.pid"
157
+ if File.exists?(pid_file)
158
+ `rm #{pid_file}`
159
+ end
160
+ runlock_file = "/var/lib/qnotifier/.runlock"
161
+ if File.exists?(runlock_file)
162
+ `rm #{runlock_file}`
163
+ end
164
+ end
165
+
166
+ def self.start
167
+ puts "Starting QNotifier..."
168
+
169
+ runlock_file = "/var/lib/qnotifier/.runlock"
170
+ if File.exists?(runlock_file)
171
+ `rm #{runlock_file}`
172
+ end
173
+
174
+ pid_file = "/var/lib/qnotifier/qnotifer.pid"
175
+ if running
176
+ puts "Daemon is already running, check pid #{pid_file}"
177
+ exit
178
+ end
179
+
180
+ pid = fork do
181
+ `echo #{Process.pid} > /var/lib/qnotifier/qnotifer.pid`
182
+ $0 = 'qnotifierd'
183
+ Process.setsid
184
+ #Process.euid = 65534
185
+ exit if fork
186
+ File.umask 0000
187
+ STDIN.reopen "/dev/null"
188
+ STDOUT.reopen "/dev/null", "a"
189
+ STDERR.reopen STDOUT
190
+ trap("TERM") {daemon.stop; exit}
191
+ loop do
192
+ cpid = fork do
193
+ require "qnotifier"
194
+ $0 = 'qnotifier-runner'
195
+ qnotifier = Qnotifier::MainProcess.new
196
+ qnotifier.run
197
+ end
198
+ Process.detach cpid
199
+ sleep 30
200
+ end
201
+ end
202
+ Process.detach pid
203
+ end
204
+
205
+ def self.stop
206
+ puts "Stopping QNotifier..."
207
+ pid_file = "/var/lib/qnotifier/qnotifer.pid"
208
+ if running
209
+ pid = `cat #{pid_file}`.to_i
210
+ Process.kill "TERM", pid
211
+ `rm /var/lib/qnotifier/qnotifer.pid`
212
+ end
213
+ end
214
+ end
215
+ end
216
+
217
+ Qnotifier::Command.run(ARGV)
data/lib/qnotifier.rb CHANGED
@@ -44,7 +44,9 @@ module Qnotifier
44
44
  end
45
45
  end
46
46
 
47
- def run
47
+ def run
48
+ Qnotifier.log.info "QNotifier Running"
49
+
48
50
  runlock_file = "/var/lib/qnotifier/.runlock"
49
51
  if File.exists?(runlock_file)
50
52
  puts "Runlock exists at #{runlock_file} - process already running? Exiting."
@@ -192,7 +194,3 @@ module Qnotifier
192
194
  end
193
195
  end
194
196
  end
195
-
196
- # The main part of the script
197
- qnotifier = Qnotifier::MainProcess.new
198
- qnotifier.run
data/lib/web_service.rb CHANGED
@@ -10,7 +10,7 @@ module Qnotifier
10
10
  attr_accessor :config
11
11
 
12
12
  def initialize
13
-
13
+ @@poll_interval = 300
14
14
  RestClient.proxy = ENV['http_proxy']
15
15
  end
16
16
 
@@ -78,7 +78,10 @@ module Qnotifier
78
78
  puts "\nNot sending data to server due to debug mode."
79
79
  return
80
80
  end
81
- return if last_run and (Time.now - last_run) <= 300
81
+ if last_run and (Time.now - last_run) <= @@poll_interval
82
+ Qnotifier.log.info "Not running yet, waiting until #{last_run + @@poll_interval}"
83
+ return
84
+ end
82
85
  Qnotifier::Storage.put("last_run", Time.now)
83
86
 
84
87
  return if reports.empty? and stats.empty?
data/qnotifier.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{qnotifier}
5
- s.version = "0.7.2"
5
+ s.version = "0.7.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Gersham Meharg"]
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.description = %q{The server side agent for the QNotifier monitoring system. This software will monitor local Linux system parameters and upload them to the QNotifier servers where users can use iPhone/iPad applications to view those stats and recieve alerts.}
12
12
  s.email = %q{gersham@qnotifier.com}
13
13
  s.executables = ["qnotifier"]
14
- s.extra_rdoc_files = ["bin/qnotifier", "lib/command.rb", "lib/plugin.rb", "lib/qnotifier.rb", "lib/storage.rb", "lib/web_service.rb"]
15
- s.files = ["Manifest", "Rakefile", "bin/qnotifier", "config/README", "config/qnotifier_config.yml", "gem-public_cert.pem", "lib/command.rb", "lib/plugin.rb", "lib/qnotifier.rb", "lib/storage.rb", "lib/web_service.rb", "lib/qnotifierd", "plugins/apache.rb", "plugins/iostat.rb", "plugins/mysql.rb", "plugins/network.rb", "plugins/nginx.rb", "plugins/passenger.rb", "plugins/processes.rb", "plugins/rails.rb", "plugins/ruby.rb", "plugins/system.rb", "plugins/urls.rb", "init.d/qnotifier", "qnotifier.gemspec"]
14
+ s.extra_rdoc_files = ["bin/qnotifier", "lib/plugin.rb", "lib/qnotifier.rb", "lib/storage.rb", "lib/web_service.rb"]
15
+ s.files = ["Manifest", "Rakefile", "bin/qnotifier", "config/README", "config/qnotifier_config.yml", "gem-public_cert.pem", "lib/plugin.rb", "lib/qnotifier.rb", "lib/storage.rb", "lib/web_service.rb", "plugins/apache.rb", "plugins/iostat.rb", "plugins/mysql.rb", "plugins/network.rb", "plugins/nginx.rb", "plugins/passenger.rb", "plugins/processes.rb", "plugins/rails.rb", "plugins/ruby.rb", "plugins/system.rb", "plugins/urls.rb", "init.d/qnotifier", "qnotifier.gemspec"]
16
16
  s.homepage = %q{http://qnotifier.com/qnotifier_gem}
17
17
  s.post_install_message = %q{Qnotifier installed, please register by running 'qnotifier' in order to register this server.}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Qnotifier"]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 2
9
- version: 0.7.2
8
+ - 3
9
+ version: 0.7.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gersham Meharg
@@ -166,7 +166,6 @@ extensions: []
166
166
 
167
167
  extra_rdoc_files:
168
168
  - bin/qnotifier
169
- - lib/command.rb
170
169
  - lib/plugin.rb
171
170
  - lib/qnotifier.rb
172
171
  - lib/storage.rb
@@ -178,12 +177,10 @@ files:
178
177
  - config/README
179
178
  - config/qnotifier_config.yml
180
179
  - gem-public_cert.pem
181
- - lib/command.rb
182
180
  - lib/plugin.rb
183
181
  - lib/qnotifier.rb
184
182
  - lib/storage.rb
185
183
  - lib/web_service.rb
186
- - lib/qnotifierd
187
184
  - plugins/apache.rb
188
185
  - plugins/iostat.rb
189
186
  - plugins/mysql.rb
metadata.gz.sig CHANGED
Binary file
data/lib/command.rb DELETED
@@ -1,189 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require "qnotifier"
3
-
4
- module Qnotifier
5
- class Command
6
-
7
- def self.run(argv)
8
- unless Process.euid == 0
9
- puts "QNotifier should be only started by root in order to set itself up"
10
- end
11
-
12
- if has_api_key?
13
- if argv.first == 'stop'
14
- stop
15
-
16
- elsif argv.first == 'start'
17
- start
18
-
19
- elsif argv.first == 'restart'
20
- stop
21
- start
22
-
23
- elsif argv.first == 'zap'
24
- zap
25
-
26
- elsif argv.first == 'reset'
27
- print "\nWould you like to reset the state of the saved variables? (y/n):"
28
- response = STDIN.gets.chomp.downcase!
29
- if response == "y" || response == "yes"
30
- `rm /var/lib/qnotifier/saved_variables.yml`
31
- end
32
-
33
- elsif argv.first == 'register'
34
- qnotifier = Qnotifier::MainProcess.new
35
- qnotifier.wipe
36
- setup_registration
37
-
38
- elsif argv.first == 'debug'
39
- puts "Running once in debug mode (use this mode to debug your plugins)\n\n"
40
- qnotifier = Qnotifier::MainProcess.new
41
- $qnotifier_debug = true
42
- qnotifier.run
43
-
44
- elsif argv.first == 'setup-directories'
45
- setup_directories
46
-
47
- else
48
- puts "usage: qnotifier start | stop | restart | zap | reset | register | debug"
49
- puts "see http://qnotifier.com for more details"
50
- end
51
-
52
- else
53
- setup_directories
54
- setup_registration
55
- end
56
- end
57
-
58
- def self.has_api_key?
59
- api_key = nil
60
- begin
61
- api_key_file = File.open("/var/lib/qnotifier/api_key")
62
- while (line = api_key_file.readline)
63
- api_key = line
64
- end
65
- rescue EOFError
66
- rescue Exception => e
67
- end
68
- if api_key
69
- return true
70
- else
71
- return false
72
- end
73
- end
74
-
75
- def self.setup_directories
76
- var_dir = "/var/lib/qnotifier"
77
- unless File.exists?(var_dir)
78
- begin
79
- puts "Creating #{var_dir}"
80
- FileUtils.mkdir_p var_dir
81
- FileUtils.mkdir_p "#{var_dir}/plugins"
82
- default_config_file = File.dirname(__FILE__) + "/../config/qnotifier_config.yml"
83
- `cp #{default_config_file} #{var_dir}/qnotifier_config.yml`
84
- readme_file = File.dirname(__FILE__) + "/../config/README"
85
- `cp #{readme_file} #{var_dir}/plugins/README`
86
- rescue Exception => e
87
- puts "Can't setup the var directory: #{e}"
88
- puts "Exiting"
89
- exit
90
- end
91
- end
92
- end
93
-
94
- def self.setup_registration
95
- puts "Starting QNotifier Agent Setup\n\n"
96
- puts "In order to use this agent you must enter the six number Registration Code that was presented to you when the server was created in the QNotifier system (in the iPhone/iPad/Website).\n\n"
97
- print "Registration Code: "
98
- register_code = STDIN.gets.chomp
99
-
100
- if register_code and register_code.size == 6
101
- qnotifier = Qnotifier::MainProcess.new
102
- if qnotifier.register(register_code)
103
- puts "\nOK, the server has been successfully registered."
104
- puts "You now can control the agent as a daemon using 'qnotifier start|stop|restart'"
105
- copy_init
106
- puts "Doing initial update..."
107
- qnotifier.run
108
- puts "\nPlease start the qnotifier daemon now ('sudo qnotifier start')"
109
- else
110
- puts "Exiting."
111
- end
112
- else
113
- puts "\nInvalid code, please enter a six number Registration Code to use this agent.\n"
114
- exit
115
- end
116
- end
117
-
118
- def self.copy_init
119
- print "\nWould you like to install the qnotifier init script in /etc/init.d? (y/n):"
120
- response = STDIN.gets.chomp.downcase!
121
- if response == "y" || response == "yes"
122
- init_file = File.dirname(__FILE__) + "/../init/qnotifier"
123
- `cp #{init_file} /etc/init.d/`
124
- end
125
- end
126
-
127
- def self.running
128
- pid_file = "/var/lib/qnotifier/qnotifer.pid"
129
- if File.exists?(pid_file)
130
- begin
131
- pid = `cat #{pid_file}`.to_i
132
- Process.getpgid(pid)
133
- return true
134
- rescue
135
- `rm #{pid_file}`
136
- return false
137
- end
138
- else
139
- return false
140
- end
141
- end
142
-
143
- def self.zap
144
- pid_file = "/var/lib/qnotifier/qnotifer.pid"
145
- if File.exists?(pid_file)
146
- `rm #{pid_file}`
147
- end
148
- end
149
-
150
- def self.start
151
- puts "Starting QNotifier..."
152
-
153
- runlock_file = "/var/lib/qnotifier/.runlock"
154
- if File.exists?(runlock_file)
155
- `rm #{runlock_file}`
156
- end
157
-
158
- pid_file = "/var/lib/qnotifier/qnotifer.pid"
159
- if running
160
- puts "Daemon is already running, check pid #{pid_file}"
161
- exit
162
- end
163
-
164
- pid = fork do
165
- $0 = 'qnotifierd'
166
- Process.setsid
167
- Process.uid = 65534 if Process.uid == 0
168
- exit if fork
169
- File.umask 0000
170
- STDIN.reopen "/dev/null"
171
- STDOUT.reopen "/dev/null", "a"
172
- STDERR.reopen STDOUT
173
- trap("TERM") {daemon.stop; exit}
174
- exec "#{File.dirname(__FILE__) }/qnotifierd"
175
- end
176
- Process.detach pid
177
- end
178
-
179
- def self.stop
180
- puts "Stopping QNotifier..."
181
- pid_file = "/var/lib/qnotifier/qnotifer.pid"
182
- if running
183
- pid = `cat #{pid_file}`.to_i
184
- Process.kill "TERM", pid
185
- `rm /var/lib/qnotifier/qnotifer.pid`
186
- end
187
- end
188
- end
189
- end
data/lib/qnotifierd DELETED
@@ -1,8 +0,0 @@
1
- #!/bin/bash
2
- echo $$ > /var/lib/qnotifier/qnotifer.pid
3
- cd `dirname $0`
4
- while [ 1 ]
5
- do
6
- ./qnotifier.rb&
7
- sleep 30
8
- done