kpm 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ module KPM
2
+ module SystemProxy
3
+ module CpuInformation
4
+ class << self
5
+ def fetch
6
+ cpu_info = nil
7
+ if OS.windows?
8
+ cpu_info = fetch_windows
9
+ elsif OS.linux?
10
+ cpu_info = fetch_linux
11
+ elsif OS.mac?
12
+ cpu_info = fetch_mac
13
+ end
14
+
15
+ cpu_info
16
+ end
17
+
18
+ def get_labels
19
+ labels = [{:label => :cpu_detail},
20
+ {:label => :value}]
21
+ labels
22
+ end
23
+
24
+ private
25
+ def fetch_linux
26
+ cpu_data = `cat /proc/cpuinfo 2>&1`.gsub("\t",'')
27
+ cpu = get_hash(cpu_data)
28
+ cpu
29
+ end
30
+
31
+ def fetch_mac
32
+ cpu_data = `system_profiler SPHardwareDataType | grep -e "Processor" -e "Cores" -e "Cache" 2>&1`
33
+ cpu = get_hash(cpu_data)
34
+ cpu
35
+ end
36
+
37
+ def fetch_windows
38
+ cpu_name = `wmic cpu get Name`.split("\n\n")
39
+ cpu_caption = `wmic cpu get Caption`.split("\n\n")
40
+ cpu_max_clock_speed = `wmic cpu get MaxClockSpeed`.split("\n\n")
41
+ cpu_device_id = `wmic cpu get DeviceId`.split("\n\n")
42
+ cpu_status = `wmic cpu get Status`.split("\n\n")
43
+
44
+ cpu = Hash.new
45
+ cpu[cpu_name[0].to_s.strip] = {:cpu_detail => cpu_name[0].to_s.strip, :value => cpu_name[1].to_s.strip}
46
+ cpu[cpu_caption[0].to_s.strip] = {:cpu_detail => cpu_caption[0].to_s.strip, :value => cpu_caption[1].to_s.strip}
47
+ cpu[cpu_max_clock_speed[0].to_s.strip] = {:cpu_detail => cpu_max_clock_speed[0].to_s.strip, :value => cpu_max_clock_speed[1].to_s.strip}
48
+ cpu[cpu_device_id[0].to_s.strip] = {:cpu_detail => cpu_device_id[0].to_s.strip, :value => cpu_device_id[1].to_s.strip}
49
+ cpu[cpu_status[0].to_s.strip] = {:cpu_detail => cpu_status[0].to_s.strip, :value => cpu_status[1].to_s.strip}
50
+
51
+ cpu
52
+ end
53
+
54
+ def get_hash(data)
55
+ cpu = Hash.new
56
+
57
+ unless data.nil?
58
+ data.split("\n").each do |info|
59
+ infos = info.split(':')
60
+
61
+ unless infos[0].to_s.strip.eql?('flags')
62
+ cpu[infos[0].to_s.strip] = {:cpu_detail => infos[0].to_s.strip, :value => infos[1].to_s.strip}
63
+ end
64
+ end
65
+ end
66
+
67
+ cpu
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,84 @@
1
+ module KPM
2
+ module SystemProxy
3
+ module DiskSpaceInformation
4
+ class << self
5
+
6
+ def fetch
7
+ disk_space_info = nil
8
+ if OS.windows?
9
+ disk_space_info = fetch_windows
10
+ elsif OS.linux?
11
+ disk_space_info = fetch_linux_mac(5)
12
+ elsif OS.mac?
13
+ disk_space_info = fetch_linux_mac(8)
14
+ end
15
+
16
+ disk_space_info
17
+ end
18
+
19
+ def get_labels
20
+ labels = []
21
+ @@data_keys.each { |key| labels.push({:label => key.gsub(' ','_').to_sym})}
22
+ labels
23
+ end
24
+
25
+ private
26
+ def fetch_linux_mac(cols_count)
27
+ disk_space_info = `df 2>&1`
28
+ disk_space = get_hash(disk_space_info,cols_count,true)
29
+ disk_space
30
+ end
31
+
32
+ def fetch_windows
33
+ disk_space_info = `wmic logicaldisk get size,freespace,caption 2>&1`
34
+ disk_space = get_hash(disk_space_info,3,false)
35
+ disk_space
36
+ end
37
+
38
+ def get_hash(data, cols_count, merge_last_two_columns)
39
+ disk_space = Hash.new
40
+
41
+ unless data.nil?
42
+
43
+ data_table = data.split("\n")
44
+
45
+ @@data_keys = data_table[0].split(' ')
46
+
47
+ if merge_last_two_columns
48
+ @@data_keys[@@data_keys.length - 2] = @@data_keys[@@data_keys.length - 2] + ' ' + @@data_keys[@@data_keys.length - 1]
49
+ @@data_keys.delete_at(@@data_keys.length - 1)
50
+ end
51
+
52
+ row_num = 0
53
+ data_table.each do |row|
54
+ cols = row.split(' ')
55
+ row_num += 1
56
+ unless cols[0].to_s.eql?(@@data_keys[0])
57
+ key = 'DiskInfo_'+row_num.to_s
58
+ disk_space[key] = Hash.new
59
+ cols.each_index do |idx|
60
+ if idx > cols_count
61
+ break
62
+ end
63
+
64
+ value = cols[idx].to_s.strip
65
+ if idx == cols_count && cols.length - 1 > idx
66
+ for i in cols_count+1..cols.length
67
+ value += ' ' + cols[i].to_s.strip
68
+ end
69
+ end
70
+
71
+ disk_space[key][@@data_keys[idx].gsub(' ','_').to_sym] = value
72
+ end
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+ disk_space
79
+ end
80
+
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,52 @@
1
+ module KPM
2
+ module SystemProxy
3
+ module EntropyAvailable
4
+ class << self
5
+
6
+ def fetch
7
+ entropy_available = nil
8
+ if OS.windows?
9
+ entropy_available = fetch_windows
10
+ elsif OS.linux?
11
+ entropy_available = fetch_linux
12
+ elsif OS.mac?
13
+ entropy_available = fetch_mac
14
+ end
15
+
16
+ entropy_available
17
+ end
18
+
19
+ def get_labels
20
+ labels = [{:label => :entropy},
21
+ {:label => :value}]
22
+ labels
23
+ end
24
+
25
+ private
26
+ def fetch_linux
27
+ entropy_available_data = `cat /proc/sys/kernel/random/entropy_avail 2>&1`.gsub("\n",'')
28
+ entropy_available = get_hash(entropy_available_data)
29
+ entropy_available
30
+ end
31
+
32
+ def fetch_mac
33
+ entropy_available = get_hash('-')
34
+ entropy_available
35
+ end
36
+
37
+ def fetch_windows
38
+ entropy_available = get_hash('-')
39
+ entropy_available
40
+ end
41
+
42
+ def get_hash(data)
43
+ entropy_available = Hash.new
44
+ entropy_available['entropy_available'] = {:entropy => 'available', :value => data}
45
+
46
+ entropy_available
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,71 @@
1
+ module KPM
2
+ module SystemProxy
3
+ module MemoryInformation
4
+ class << self
5
+
6
+ def fetch
7
+ memory_info = nil
8
+ if OS.windows?
9
+ memory_info = fetch_windows
10
+ elsif OS.linux?
11
+ memory_info = fetch_linux
12
+ elsif OS.mac?
13
+ memory_info = fetch_mac
14
+ end
15
+
16
+ memory_info
17
+ end
18
+
19
+ def get_labels
20
+ labels = [{:label => :memory_detail},
21
+ {:label => :value}]
22
+ labels
23
+ end
24
+
25
+ private
26
+ def fetch_linux
27
+ mem_data = `cat /proc/meminfo 2>&1`.gsub("\t",'')
28
+ mem = get_hash(mem_data)
29
+ mem
30
+ end
31
+
32
+ def fetch_mac
33
+ mem_data = `vm_stat 2>&1`.gsub(".",'')
34
+ mem = get_hash(mem_data)
35
+
36
+ mem.each_key do |key|
37
+ mem[key][:value] = ((mem[key][:value].to_i * 4096) / 1024 / 1024).to_s + 'MB'
38
+ mem[key][:memory_detail] = mem[key][:memory_detail].gsub('Pages','Memory')
39
+ end
40
+
41
+ mem_total_data = `system_profiler SPHardwareDataType | grep " Memory:" 2>&1`
42
+ mem_total = get_hash(mem_total_data)
43
+
44
+ mem = mem_total.merge(mem)
45
+
46
+ mem
47
+ end
48
+
49
+ def fetch_windows
50
+ mem_data = `systeminfo | findstr /C:"Total Physical Memory" /C:"Available Physical Memory"`
51
+ mem = get_hash(mem_data)
52
+ mem
53
+ end
54
+
55
+ def get_hash(data)
56
+ mem = Hash.new
57
+
58
+ unless data.nil?
59
+ data.split("\n").each do |info|
60
+ infos = info.split(':')
61
+ mem[infos[0].to_s.strip] = {:memory_detail => infos[0].to_s.strip, :value => infos[1].to_s.strip}
62
+ end
63
+ end
64
+
65
+ mem
66
+ end
67
+
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,66 @@
1
+ module KPM
2
+ module SystemProxy
3
+ module OsInformation
4
+ class << self
5
+
6
+ def fetch
7
+ os_information = nil
8
+ if OS.windows?
9
+ os_information = fetch_windows
10
+ elsif OS.linux?
11
+ os_information = fetch_linux
12
+ elsif OS.mac?
13
+ os_information = fetch_mac
14
+ end
15
+
16
+ os_information
17
+ end
18
+
19
+ def get_labels
20
+ labels = [{:label => :os_detail},
21
+ {:label => :value}]
22
+ labels
23
+ end
24
+
25
+ private
26
+ def fetch_linux
27
+ os_data = `lsb_release -a 2>&1`
28
+
29
+ if os_data.nil? || os_data.include?('lsb_release: not found')
30
+ os_data = `cat /etc/issue 2>&1`
31
+ os_data = 'Description:'+os_data.gsub('\n \l','')
32
+ end
33
+
34
+ os = get_hash(os_data)
35
+ os
36
+ end
37
+
38
+ def fetch_mac
39
+ os_data = `sw_vers`
40
+ os = get_hash(os_data)
41
+ os
42
+ end
43
+
44
+ def fetch_windows
45
+ os_data = `systeminfo | findstr /C:"OS"`
46
+ os = get_hash(os_data)
47
+ os
48
+ end
49
+
50
+ def get_hash(data)
51
+ os = Hash.new
52
+
53
+ unless data.nil?
54
+ data.split("\n").each do |info|
55
+ infos = info.split(':')
56
+ os[infos[0].to_s.strip] = {:os_detail => infos[0].to_s.strip, :value => infos[1].to_s.strip}
57
+ end
58
+ end
59
+
60
+ os
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'cpu_information'
2
+ require_relative 'memory_information'
3
+ require_relative 'disk_space_information'
4
+ require_relative 'entropy_available'
5
+ require_relative 'os_information'
6
+ module KPM
7
+ module SystemProxy
8
+
9
+ module OS
10
+ def OS.windows?
11
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RbConfig::CONFIG["host_os"]) != nil
12
+ end
13
+
14
+ def OS.mac?
15
+ (/darwin/ =~ RbConfig::CONFIG["host_os"]) != nil
16
+ end
17
+
18
+ def OS.unix?
19
+ !OS.windows?
20
+ end
21
+
22
+ def OS.linux?
23
+ OS.unix? and not OS.mac?
24
+ end
25
+ end
26
+
27
+ end
28
+ end
data/lib/kpm/tasks.rb CHANGED
@@ -38,7 +38,8 @@ module KPM
38
38
  desc 'install config_file', 'Install Kill Bill server and plugins according to the specified YAML configuration file.'
39
39
  def install(config_file=nil)
40
40
  help = Installer.from_file(config_file).install(options[:force_download], options[:verify_sha1])
41
- say help, :green unless help.nil?
41
+ help = JSON(help)
42
+ say help['help'], :green unless help['help'].nil?
42
43
  end
43
44
 
44
45
  method_option :destination,
@@ -428,8 +429,13 @@ module KPM
428
429
  desc 'system', 'Gather information about the system'
429
430
  def system
430
431
  system = KPM::System.new
431
- system.information(options[:bundles_dir], options[:as_json], options[:config_file], options[:kaui_web_path],
432
+ information = system.information(options[:bundles_dir], options[:as_json], options[:config_file], options[:kaui_web_path],
432
433
  options[:killbill_web_path])
434
+
435
+ if options[:as_json]
436
+ puts information
437
+ end
438
+
433
439
  end
434
440
 
435
441
  method_option :export,
@@ -593,6 +599,99 @@ module KPM
593
599
  end
594
600
 
595
601
 
602
+ method_option :account_export,
603
+ :type => :string,
604
+ :default => nil,
605
+ :desc => 'export account for a provided id.'
606
+ method_option :log_dir,
607
+ :type => :string,
608
+ :default => nil,
609
+ :desc => '(Optional) Log directory if the default tomcat location has changed'
610
+ method_option :config_file,
611
+ :type => :string,
612
+ :default => nil,
613
+ :desc => 'Yml that contains killbill api connection and DB connection'
614
+ method_option :killbill_api_credentials,
615
+ :type => :array,
616
+ :default => nil,
617
+ :desc => 'Killbill api credentials <api_key> <api_secrets>'
618
+ method_option :killbill_credentials,
619
+ :type => :array,
620
+ :default => nil,
621
+ :desc => 'Killbill credentials <user> <password>'
622
+ method_option :killbill_url,
623
+ :type => :string,
624
+ :default => nil,
625
+ :desc => 'Killbill URL ex. http://127.0.0.1:8080'
626
+ method_option :database_name,
627
+ :type => :string,
628
+ :default => nil,
629
+ :desc => 'DB name to connect'
630
+ method_option :database_credentials,
631
+ :type => :array,
632
+ :default => nil,
633
+ :desc => 'DB credentials <user> <password>'
634
+ method_option :database_host,
635
+ :type => :string,
636
+ :default => nil,
637
+ :desc => 'Database Host name'
638
+ method_option :kaui_web_path,
639
+ :type => :string,
640
+ :default => nil,
641
+ :desc => 'Path for the KAUI web app'
642
+ method_option :killbill_web_path,
643
+ :type => :string,
644
+ :default => nil,
645
+ :desc => 'Path for the killbill web app'
646
+ desc 'diagnostic', 'exports and \'zips\' the account data, system, logs and tenant configurations'
647
+ def diagnostic
648
+ logger.info 'Please wait processing the request!!!'
649
+ begin
650
+ if options[:account_export] && options[:account_export] == 'account_export'
651
+ raise Interrupt,'--account_export, please provide a valid account id'
652
+ end
653
+
654
+ if options[:killbill_url] && /https?:\/\/[\S]+/.match(options[:killbill_url]).nil?
655
+ raise Interrupt,'--killbill_url, required format -> http(s)://something'
656
+ end
657
+
658
+ if options[:killbill_api_credentials] && options[:killbill_api_credentials].size != 2
659
+ raise Interrupt,'--killbill_api_credentials, required format -> <api_key> <api_secrets>'
660
+ end
661
+
662
+ if options[:killbill_credentials] && options[:killbill_credentials].size != 2
663
+ raise Interrupt,'--killbill_credentials, required format -> <user> <password>'
664
+ end
665
+
666
+ if options[:database_credentials] && options[:database_credentials].size != 2
667
+ raise Interrupt,'--database_credentials, required format -> <user> <password>'
668
+ end
669
+
670
+ if options[:database_name] && options[:database_name] == :database_name.to_s
671
+ raise Interrupt,'--database_credentials, please provide a valid database name'
672
+ end
673
+
674
+ if options[:kaui_web_path] && options[:kaui_web_path] == :kaui_web_path.to_s
675
+ raise Interrupt,'--kaui_web_path, please provide a valid kaui web path '
676
+ end
677
+
678
+ if options[:killbill_web_path] && options[:killbill_web_path] == :killbill_web_path.to_s
679
+ raise Interrupt,'--killbill_web_path, please provide a valid killbill web path'
680
+ end
681
+
682
+ diagnostic = KPM::DiagnosticFile.new(options[:config_file],options[:killbill_api_credentials],options[:killbill_credentials],
683
+ options[:killbill_url],options[:database_name],options[:database_credentials],
684
+ options[:database_host], options[:kaui_web_path], options[:killbill_web_path],logger)
685
+ diagnostic.export_data(options[:account_export], options[:log_dir])
686
+
687
+ rescue Exception => e
688
+ logger.error "\e[91;1m#{e.message}\e[0m"
689
+ if not e.is_a?(Interrupt)
690
+ logger.error e.backtrace.join("\n")
691
+ end
692
+ end
693
+ end
694
+
596
695
  map :pull_ruby_plugin => :install_ruby_plugin,
597
696
  :pull_java_plugin => :install_java_plugin
598
697