panda-motd 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 324ec514bbb141949c82866eed44d830d6f0f768824f42cda912f872f205bdc8
4
- data.tar.gz: 867433a26a6277120037b51c7f16b0eb6cb32edac085f1f245048c7097148829
3
+ metadata.gz: b2fd6e0a2e577fc5da802286b310b10ba6a6a6156e18018e8752e7d6721eb722
4
+ data.tar.gz: 276d6515eb28126be934ed82c3cf128ca509150325b1ce06b5bd8db95f81c0d6
5
5
  SHA512:
6
- metadata.gz: bec0220f18e5b3c5c2f32958ba93cd463efe92ce87dee363b9dd5ee2aec2ab7579b3ce1cc6794dae483f82b8b8ba38d15d974ef77a8bb91b2524fd5ff12a4180
7
- data.tar.gz: 71e8cba32a1936bdf7304c296364ef2dc2aeb9cce2f4a9fb747db3bd97bee4f4ae8c5c4130ca0c6abc9a719f78ad01f98215b4ede31b72d48736e7c871a36fc2
6
+ metadata.gz: 8d7ba00265bd290738b77b3493e0ada6cc4bd42f13dd8dfdcd69fdf1eb1143396299bab7da17ffa597d4507d0979043511642eafcde06f8a62208274a1ef389b
7
+ data.tar.gz: 1790ef2779623a5c8d9cf00cb7b56d20b4130ee52d8894bc2545a7b7ff1ceeb7e5c775382c961d6123050fddc6de88ee24dc179dbb1487b65df6e760e227dd4d
@@ -70,7 +70,8 @@ class Filesystems
70
70
  total_ticks = name_col_size_with_padding + 18
71
71
  used_ticks = (total_ticks * (percentage_used.to_f / 100)).round
72
72
 
73
- result += " [#{('=' * used_ticks).send(percentage_color(percentage_used))}#{('=' * (total_ticks - used_ticks)).light_black}]\n"
73
+ result += " [#{('=' * used_ticks).send(percentage_color(percentage_used))}#{('=' * (total_ticks - used_ticks)).light_black}]"
74
+ result += "\n" unless filesystem == @results.last
74
75
  end
75
76
 
76
77
  return result
@@ -0,0 +1,70 @@
1
+ require 'date'
2
+
3
+ class LastLogin
4
+ attr_reader :name, :errors, :results
5
+
6
+ def initialize(motd)
7
+ @name = 'last_login'
8
+ @motd = motd
9
+ @config = motd.config.component_config(@name)
10
+ @errors = []
11
+ end
12
+
13
+ def process
14
+ @users = @config['users']
15
+ @results = parse_last_logins(@users)
16
+ end
17
+
18
+ def to_s
19
+ result = "Last Login:\n"
20
+
21
+ @results.each do |user, logins|
22
+ result += " #{user}:\n"
23
+ location_string_size = logins.map { |l| l[:location].length }.max
24
+ logins.each do |login|
25
+ location_part = login[:location].ljust(location_string_size, ' ')
26
+ start_part = login[:time_start].strftime('%m/%d/%Y %I:%M%p')
27
+
28
+ end_part = if login[:time_end].is_a? String # still logged in text
29
+ login[:time_end].green
30
+ else
31
+ "#{((login[:time_end] - login[:time_start]) * 24 * 60).to_i} minutes"
32
+ end
33
+
34
+ result += " from #{location_part} at #{start_part} (#{end_part})\n"
35
+ end
36
+ result += ' no logins found for user.' if logins.empty?
37
+ end
38
+
39
+ return result
40
+ end
41
+
42
+ private
43
+
44
+ def parse_last_logins(users)
45
+ all_logins = {}
46
+ users.each_with_index do |(username, num_logins), i|
47
+ user_logins = []
48
+ cmd_result = `last --time-format=iso #{username}`
49
+ cmd_result.split("\n").each do |entry|
50
+ next unless entry.start_with? username
51
+ data = entry.split(/(?:\s{2,})|(?:\s-\s)/)
52
+
53
+ time_end = data[4] == 'still logged in' ? data[4] : DateTime.parse(data[4])
54
+
55
+ user_logins << {
56
+ username: username,
57
+ location: data[2],
58
+ time_start: DateTime.parse(data[3]),
59
+ time_end: time_end
60
+ }
61
+
62
+ break if user_logins.count >= num_logins
63
+ end
64
+
65
+ all_logins[username.to_sym] = user_logins
66
+ end
67
+
68
+ return all_logins
69
+ end
70
+ end
@@ -27,7 +27,8 @@ class Config
27
27
  service_status: ServiceStatus,
28
28
  uptime: Uptime,
29
29
  ssl_certificates: SSLCertificates,
30
- filesystems: Filesystems
30
+ filesystems: Filesystems,
31
+ last_login: LastLogin
31
32
  }
32
33
  end
33
34
 
@@ -38,5 +39,6 @@ class Config
38
39
 
39
40
  def load_config(file_path)
40
41
  @config = YAML.safe_load(File.read(file_path))
42
+ @config['components'] = [] if @config['components'].nil?
41
43
  end
42
44
  end
@@ -6,7 +6,7 @@
6
6
  components:
7
7
  #####
8
8
  # ASCII Text Art
9
- # Generates ASCII pictures of strings.
9
+ # Generates ASCII pictures of strings. Currently only shows the hostname.
10
10
  #
11
11
  # Settings
12
12
  # font: The figlet font to render the text with. All supported fonts
@@ -87,3 +87,20 @@ components:
87
87
  # filesystems:
88
88
  # /dev/sda1: Ubuntu
89
89
  # /dev/sdc1: Data
90
+
91
+
92
+ #####
93
+ # Last Login
94
+ # Displays previous login information for users.
95
+ #
96
+ # Settings
97
+ # users: A list of user names which you are interested in receiving login
98
+ # information about. The key is the username, and the value is the number
99
+ # of recent logins you'd like to display.
100
+ #####
101
+
102
+ # last_login:
103
+ # enabled: true
104
+ # users:
105
+ # taylor: 2
106
+ # stoyan: 1
@@ -1,4 +1,4 @@
1
1
  class PandaMOTD
2
2
  #:nodoc:
3
- VERSION ||= '0.0.4'.freeze
3
+ VERSION ||= '0.0.5'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda-motd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Thurlow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-12 00:00:00.000000000 Z
11
+ date: 2018-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: artii
@@ -190,6 +190,7 @@ files:
190
190
  - lib/panda_motd/component_error.rb
191
191
  - lib/panda_motd/components/ascii_text_art.rb
192
192
  - lib/panda_motd/components/filesystems.rb
193
+ - lib/panda_motd/components/last_login.rb
193
194
  - lib/panda_motd/components/service_status.rb
194
195
  - lib/panda_motd/components/ssl_certificates.rb
195
196
  - lib/panda_motd/components/uptime.rb