knife-goiardi-event-log 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +25 -1
- data/lib/chef/goiardi/knife_helpers.rb +58 -14
- data/lib/chef/knife/goiardi_gel_delete.rb +1 -1
- data/lib/chef/knife/goiardi_gel_list.rb +68 -3
- data/lib/chef/knife/goiardi_gel_purge.rb +1 -1
- data/lib/chef/knife/goiardi_gel_show.rb +1 -1
- data/lib/knife-goiardi-event-log/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -11,6 +11,13 @@ goiardi gel show`, `knife goiardi gel delete` and `knife goiardi gel purge`.
|
|
11
11
|
`knife goiardi gel list` returns a list of logged events. A limit may be
|
12
12
|
specified with `--limit`; the default limit is 15. An offset may also be specified; the default offset is 0.
|
13
13
|
|
14
|
+
Results may be further narrowed using the `--starttime`, `--endtime`, `--doer`,
|
15
|
+
`--object-type`, and `--object-name` options. The time options narrow the
|
16
|
+
results by date range, the `--doer` option searches for events done by the named
|
17
|
+
user, and `--object-type` and `--object-name` limit the search to objects of the
|
18
|
+
given type and name respectively. NB: these options only work with goiardi 0.6.0
|
19
|
+
and above. Earlier versions that support event logging will ignore them.
|
20
|
+
|
14
21
|
`knife goiardi gel show [id]` gives a detailed listing of a particular event log
|
15
22
|
item.
|
16
23
|
|
@@ -23,7 +30,7 @@ were purged.
|
|
23
30
|
|
24
31
|
## Installation
|
25
32
|
|
26
|
-
The best way to install this plugin is with gem
|
33
|
+
The best way to install this plugin is with gem:
|
27
34
|
|
28
35
|
$ gem install knife-goiardi-event-log
|
29
36
|
|
@@ -50,3 +57,20 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
50
57
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
51
58
|
See the License for the specific language governing permissions and
|
52
59
|
limitations under the License.
|
60
|
+
|
61
|
+
This plugin also contains code from the Chef knife-reporting plugin, available
|
62
|
+
under the terms of the Apache 2.0 license:
|
63
|
+
|
64
|
+
Copyright 2013-2014, Chef
|
65
|
+
|
66
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
67
|
+
you may not use this file except in compliance with the License.
|
68
|
+
You may obtain a copy of the License at
|
69
|
+
|
70
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
71
|
+
|
72
|
+
Unless required by applicable law or agreed to in writing, software
|
73
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
74
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
75
|
+
See the License for the specific language governing permissions and
|
76
|
+
limitations under the License.
|
@@ -1,19 +1,63 @@
|
|
1
1
|
class Chef
|
2
2
|
module Goiardi
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
module Gel
|
4
|
+
module KnifeHelpers
|
5
|
+
def format_object_type(obj)
|
6
|
+
if obj == "*cookbook.CookbookVersion"
|
7
|
+
"cookbook_version"
|
8
|
+
else
|
9
|
+
obj =~ /^\*?(\w+)\.?/
|
10
|
+
$1 || obj
|
11
|
+
end
|
12
|
+
end
|
13
|
+
def format_time(timestamp)
|
14
|
+
Time.parse(timestamp).strftime("%c")
|
15
|
+
end
|
16
|
+
|
17
|
+
def format_event(gel)
|
18
|
+
gel["object_type"] = format_object_type(gel["object_type"])
|
19
|
+
gel["actor_info"] = JSON.parse(gel["actor_info"])
|
20
|
+
gel["extended_info"] = JSON.parse(gel["extended_info"])
|
21
|
+
gel["time"] = format_time(gel["time"])
|
22
|
+
gel
|
23
|
+
end
|
24
|
+
|
25
|
+
# Code below adapted from the knife-reporting plugin
|
26
|
+
def apply_time_args()
|
27
|
+
if config[:start_time]
|
28
|
+
start_time = convert_to_unix_timestamps(config[:start_time])
|
29
|
+
else
|
30
|
+
start_time = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
if config[:end_time]
|
34
|
+
end_time = convert_to_unix_timestamps(config[:end_time])
|
35
|
+
else
|
36
|
+
end_time = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
return start_time, end_time
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def convert_to_unix_timestamps(time_to_change)
|
45
|
+
if config[:unix_timestamps]
|
46
|
+
new_time = time_to_change.to_i
|
47
|
+
else
|
48
|
+
# Take user supplied input, assumes it is in a valid date format,
|
49
|
+
# convert to a date object to ensure we have the proper date format for
|
50
|
+
# passing to the time object (but converting is not a validation step,
|
51
|
+
# so bad user input will still be bad)
|
52
|
+
# then convert to a time object, and then convert to a unix timestamp
|
53
|
+
# An error could potentially be thrown if the conversions don't work
|
54
|
+
# This does work on windows - to_i on time even on windows still returns a unix timestamp
|
55
|
+
# Verified on ruby 1.9.3 on a windows 2000 ami on aws
|
56
|
+
new_time = Time.parse(Date.strptime(time_to_change, '%m-%d-%Y').to_s).to_i
|
57
|
+
end
|
58
|
+
|
59
|
+
return new_time
|
60
|
+
end
|
17
61
|
end
|
18
62
|
end
|
19
63
|
end
|
@@ -6,7 +6,7 @@ class Chef
|
|
6
6
|
class GoiardiGelList < Chef::Knife
|
7
7
|
banner "knife goiardi gel list [options]"
|
8
8
|
|
9
|
-
include Chef::Goiardi::KnifeHelpers
|
9
|
+
include Chef::Goiardi::Gel::KnifeHelpers
|
10
10
|
|
11
11
|
option :limit,
|
12
12
|
:long => '--limit N',
|
@@ -20,22 +20,87 @@ class Chef
|
|
20
20
|
:required => false,
|
21
21
|
:description => "Offset to fetch events from. Default is 0."
|
22
22
|
|
23
|
+
option :start_time,
|
24
|
+
:long => '--starttime MM-DD-YYYY',
|
25
|
+
:short => '-s MM-DD-YYYY',
|
26
|
+
:required => false,
|
27
|
+
:description => 'Find events logged at a time great than or equal to the date provided. If the -u option is provided unix timestamps can be given instead.'
|
28
|
+
|
29
|
+
option :end_time,
|
30
|
+
:long => '--endtime MM-DD-YYYY',
|
31
|
+
:short => '-e MM-DD-YYYY',
|
32
|
+
:required => false,
|
33
|
+
:description => 'Find events logged at a time less than or equal to the date provided. If the -u option is provided unix timestamps can be given instead.'
|
34
|
+
|
35
|
+
option :unix_timestamps,
|
36
|
+
:long => '--unixtimestamps',
|
37
|
+
:short => '-u',
|
38
|
+
:required => false,
|
39
|
+
:boolean => true,
|
40
|
+
:description => 'Indicates start and end times are given as unix time stamps and not date formats.'
|
41
|
+
|
42
|
+
option :object_type,
|
43
|
+
:long => '--object-type N',
|
44
|
+
:short => '-T N',
|
45
|
+
:required => false,
|
46
|
+
:description => 'Narrow search for logged events to this object type (node, role, environment, etc.)'
|
47
|
+
|
48
|
+
option :object_name,
|
49
|
+
:long => '--object-name N',
|
50
|
+
:short => '-N N',
|
51
|
+
:required => false,
|
52
|
+
:description => 'Narrow search for logged events to objects with this name.'
|
53
|
+
|
54
|
+
option :doer,
|
55
|
+
:long => '--doer N',
|
56
|
+
:short => '-D N',
|
57
|
+
:required => false,
|
58
|
+
:description => 'Narrow search for logged events to actions performed by the given user or client.'
|
59
|
+
|
23
60
|
def run
|
24
61
|
@rest = Chef::REST.new(Chef::Config[:chef_server_url])
|
25
62
|
rows = config[:limit] || 15
|
26
63
|
offset = config[:offset] || 0
|
27
|
-
|
64
|
+
start_time, end_time = apply_time_args()
|
65
|
+
list = @rest.get_rest(generate_query(rows, offset, start_time, end_time, config), false, {})
|
28
66
|
list.map! do |l|
|
29
67
|
l["event"]["object_type"] = format_object_type(l["event"]["object_type"])
|
30
|
-
{ :event => { :id => l["event"]["id"],
|
68
|
+
li = { :event => { :id => l["event"]["id"],
|
31
69
|
:action => l["event"]["action"],
|
32
70
|
:name => l["event"]["object_name"],
|
33
71
|
:type => l["event"]["object_type"],
|
34
72
|
:time => format_time(l["event"]["time"]) } }
|
73
|
+
if config[:doer]
|
74
|
+
actor_info = JSON.parse(l["event"]["actor_info"])
|
75
|
+
li[:event][:performed_by] = actor_info["username"]
|
76
|
+
end
|
77
|
+
li
|
35
78
|
end
|
36
79
|
output(list)
|
37
80
|
end
|
38
81
|
|
82
|
+
private
|
83
|
+
|
84
|
+
def generate_query(rows, offset, start_time, end_time, options)
|
85
|
+
query = "events?limit=#{rows}&offset=#{offset}"
|
86
|
+
if start_time
|
87
|
+
query += "&from=#{start_time}"
|
88
|
+
end
|
89
|
+
if end_time
|
90
|
+
query += "&until=#{end_time}"
|
91
|
+
end
|
92
|
+
if options[:object_type]
|
93
|
+
query += "&object_type=#{options[:object_type]}"
|
94
|
+
end
|
95
|
+
if options[:object_name]
|
96
|
+
query += "&object_name=#{options[:object_name]}"
|
97
|
+
end
|
98
|
+
if options[:doer]
|
99
|
+
query += "&doer=#{options[:doer]}"
|
100
|
+
end
|
101
|
+
query
|
102
|
+
end
|
103
|
+
|
39
104
|
end
|
40
105
|
end
|
41
106
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-goiardi-event-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|