cpee-logging-xes-yaml 1.0.6 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cpee-logging-xes-yaml.gemspec +1 -1
- data/lib/cpee-logging-xes-yaml/logging.rb +5 -56
- data/lib/cpee-logging-xes-yaml/tools.rb +186 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d956eefad6c946b59eb9fabc244d9349844f4b502cea3c04f49b8deb0ec50751
|
4
|
+
data.tar.gz: 393afba26427d6cf6ad65154c6d8fa485d4c09baef23d13d526fbfdc9b0ee968
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95046ec653cbeffb1122109f9acec7e71387efd94c732235790bb28cc824f74ec0e4a6d6b03ad7a03d268b303b98c0dc71697a627ef250631a75b7d0a89bc7f9
|
7
|
+
data.tar.gz: eefc314f27a41321e204d28c535ce27572ed58b4dc1b157bedda3c3169f133b45d5a1e3d0273c9db77130b20fb6babed433a9ad2e9647c64794245c5a4908bac
|
@@ -21,65 +21,14 @@ require 'yaml'
|
|
21
21
|
require 'riddl/server'
|
22
22
|
require 'time'
|
23
23
|
|
24
|
+
require_relative 'tools'
|
25
|
+
|
24
26
|
module CPEE
|
25
27
|
module Logging
|
26
28
|
|
27
29
|
SERVER = File.expand_path(File.join(__dir__,'logging.xml'))
|
28
30
|
|
29
|
-
class Handler < Riddl::Implementation
|
30
|
-
def doc(topic,event_name,log_dir,template,payload)
|
31
|
-
notification = JSON.parse(payload)
|
32
|
-
instance = notification['instance-uuid']
|
33
|
-
return unless instance
|
34
|
-
|
35
|
-
instancenr = notification['instance']
|
36
|
-
content = notification['content']
|
37
|
-
activity = content['activity']
|
38
|
-
parameters = content['parameters']
|
39
|
-
receiving = content['received']
|
40
|
-
|
41
|
-
log = YAML::load(File.read(template))
|
42
|
-
log["log"]["trace"]["concept:name"] ||= instancenr
|
43
|
-
log["log"]["trace"]["cpee:name"] ||= notification['instance-name'] if notification['instance-name']
|
44
|
-
log["log"]["trace"]["cpee:instance"] ||= instance
|
45
|
-
File.open(File.join(log_dir,instance+'.xes.yaml'),'w'){|f| f.puts log.to_yaml} unless File.exists? File.join(log_dir,instance+'.xes.yaml')
|
46
|
-
event = {}
|
47
|
-
event["concept:instance"] = instancenr
|
48
|
-
event["concept:name"] = content["label"] if content["label"]
|
49
|
-
if content["endpoint"]
|
50
|
-
event["concept:endpoint"] = content["endpoint"]
|
51
|
-
end
|
52
|
-
event["id:id"] = (activity.nil? || activity == "") ? 'external' : activity
|
53
|
-
event["cpee:activity"] = event["id:id"]
|
54
|
-
event["cpee:activity_uuid"] = content['activity-uuid'] if content['activity-uuid']
|
55
|
-
event["cpee:instance"] = instance
|
56
|
-
case event_name
|
57
|
-
when 'receiving', 'change', 'instantiation'
|
58
|
-
event["lifecycle:transition"] = "unknown"
|
59
|
-
when 'done'
|
60
|
-
event["lifecycle:transition"] = "complete"
|
61
|
-
else
|
62
|
-
event["lifecycle:transition"] = "start"
|
63
|
-
end
|
64
|
-
event["cpee:lifecycle:transition"] = "#{topic}/#{event_name}"
|
65
|
-
event["cpee:state"] = content['state'] if content['state']
|
66
|
-
event["cpee:description"] = content['dslx'] if content['dslx']
|
67
|
-
unless parameters["arguments"]&.nil?
|
68
|
-
event["data"] = parameters["arguments"]
|
69
|
-
end
|
70
|
-
if content['changed']&.any?
|
71
|
-
event["data"] = content['values']
|
72
|
-
end
|
73
|
-
if receiving && !receiving.empty?
|
74
|
-
event["raw"] = receiving
|
75
|
-
end
|
76
|
-
event["time:timestamp"]= event['cpee:timestamp'] || Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z")
|
77
|
-
File.open(File.join(log_dir,instance+'.xes.yaml'),'a') do |f|
|
78
|
-
f << {'event' => event}.to_yaml
|
79
|
-
end
|
80
|
-
nil
|
81
|
-
end
|
82
|
-
|
31
|
+
class Handler < Riddl::Implementation
|
83
32
|
def response
|
84
33
|
topic = @p[1].value
|
85
34
|
event_name = @p[2].value
|
@@ -87,11 +36,11 @@ module CPEE
|
|
87
36
|
template = @a[1]
|
88
37
|
notification = @p[3].value.read
|
89
38
|
EM.defer do
|
90
|
-
doc topic, event_name, log_dir, template, notification
|
39
|
+
CPEE::Logging::doc topic, event_name, log_dir, template, notification
|
91
40
|
end
|
92
41
|
nil
|
93
42
|
end
|
94
|
-
end
|
43
|
+
end
|
95
44
|
|
96
45
|
def self::implementation(opts)
|
97
46
|
opts[:log_dir] ||= File.join(__dir__,'logs')
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'weel'
|
2
|
+
|
3
|
+
class StreamPoint
|
4
|
+
attr_accessor :value, :timestamp, :source, :meta
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@value = nil
|
8
|
+
@timestamp = Time.now
|
9
|
+
@source = nil
|
10
|
+
@meta = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_h(id)
|
14
|
+
tp = { 'stream:point' => { } }
|
15
|
+
tp['stream:point']['stream:id'] = id
|
16
|
+
tp['stream:point']['stream:value'] = @value
|
17
|
+
tp['stream:point']['stream:timestamp'] = @timestamp
|
18
|
+
tp['stream:point']['stream:source'] = @source unless @source.nil?
|
19
|
+
tp['stream:point']['stream:meta'] = @meta unless @meta.nil?
|
20
|
+
tp
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module CPEE
|
25
|
+
module Logging
|
26
|
+
|
27
|
+
def self::extract_probes(where,xml)
|
28
|
+
XML::Smart::string(xml) do |doc|
|
29
|
+
doc.register_namespace 'd', 'http://cpee.org/ns/description/1.0'
|
30
|
+
doc.find('//d:call').each do |c|
|
31
|
+
c.find('d:annotations/d:_context_data_analysis/d:probes').each do |p|
|
32
|
+
File.write(where + '_' + c.attributes['id'] + '.probe', p.dump)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self::extract_sensor(rs,code,result)
|
39
|
+
result.map! do |res|
|
40
|
+
if res['mimetype'].nil?
|
41
|
+
res['value']
|
42
|
+
elsif res['mimetype'] == 'application/json'
|
43
|
+
JSON::parse(res['data'])
|
44
|
+
elsif res['mimetype'] == 'application/xml' || res['mimetype'] == 'text/xml'
|
45
|
+
XML::Smart::string(res['data']) rescue nil
|
46
|
+
elsif res.mimetype == 'text/yaml'
|
47
|
+
YAML::load(res['data']) rescue nil
|
48
|
+
elsif result[0].mimetype == 'text/plain'
|
49
|
+
t = res['data']
|
50
|
+
if t.start_with?("<?xml version=")
|
51
|
+
t = XML::Smart::string(t)
|
52
|
+
else
|
53
|
+
t = t.to_f if t == t.to_f.to_s
|
54
|
+
t = t.to_i if t == t.to_i.to_s
|
55
|
+
end
|
56
|
+
t
|
57
|
+
elsif res.mimetype == 'text/html'
|
58
|
+
t = res['data']
|
59
|
+
t = t.to_f if t == t.to_f.to_s
|
60
|
+
t = t.to_i if t == t.to_i.to_s
|
61
|
+
t
|
62
|
+
else
|
63
|
+
res['data']
|
64
|
+
end
|
65
|
+
end
|
66
|
+
result = result[0] if result.length == 1
|
67
|
+
rs.instance_eval(code)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self::persist_values(where,values)
|
71
|
+
unless File.exists?(where)
|
72
|
+
File.write(where,'{}')
|
73
|
+
end
|
74
|
+
f = File.open(where,'r+')
|
75
|
+
f.flock(File::LOCK_EX)
|
76
|
+
json = JSON::load(f).merge(values)
|
77
|
+
f.rewind
|
78
|
+
f.truncate(0)
|
79
|
+
f.write(JSON.generate(json))
|
80
|
+
f.close
|
81
|
+
end
|
82
|
+
|
83
|
+
def self::doc(topic,event_name,log_dir,template,payload)
|
84
|
+
notification = JSON.parse(payload)
|
85
|
+
instance = notification['instance-uuid']
|
86
|
+
return unless instance
|
87
|
+
|
88
|
+
instancenr = notification['instance']
|
89
|
+
content = notification['content']
|
90
|
+
activity = content['activity']
|
91
|
+
parameters = content['parameters']
|
92
|
+
receiving = content['received']
|
93
|
+
|
94
|
+
if content['dslx']
|
95
|
+
CPEE::Logging::extract_probes(File.join(log_dir,instance),content['dslx'])
|
96
|
+
end
|
97
|
+
|
98
|
+
if topic == 'dataelements' && event_name == 'change'
|
99
|
+
if content['changed']&.any?
|
100
|
+
CPEE::Logging::persist_values(File.join(log_dir,instance + '.data.json'),content['values'])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
log = YAML::load(File.read(template))
|
105
|
+
log["log"]["trace"]["concept:name"] ||= instancenr
|
106
|
+
log["log"]["trace"]["cpee:name"] ||= notification['instance-name'] if notification['instance-name']
|
107
|
+
log["log"]["trace"]["cpee:instance"] ||= instance
|
108
|
+
File.open(File.join(log_dir,instance+'.xes.yaml'),'w'){|f| f.puts log.to_yaml} unless File.exists? File.join(log_dir,instance+'.xes.yaml')
|
109
|
+
event = {}
|
110
|
+
event["concept:instance"] = instancenr
|
111
|
+
event["concept:name"] = content["label"] if content["label"]
|
112
|
+
if content["endpoint"]
|
113
|
+
event["concept:endpoint"] = content["endpoint"]
|
114
|
+
end
|
115
|
+
event["id:id"] = (activity.nil? || activity == "") ? 'external' : activity
|
116
|
+
event["cpee:activity"] = event["id:id"]
|
117
|
+
event["cpee:activity_uuid"] = content['activity-uuid'] if content['activity-uuid']
|
118
|
+
event["cpee:instance"] = instance
|
119
|
+
case event_name
|
120
|
+
when 'receiving', 'change', 'instantiation'
|
121
|
+
event["lifecycle:transition"] = "unknown"
|
122
|
+
when 'done'
|
123
|
+
event["lifecycle:transition"] = "complete"
|
124
|
+
else
|
125
|
+
event["lifecycle:transition"] = "start"
|
126
|
+
end
|
127
|
+
event["cpee:lifecycle:transition"] = "#{topic}/#{event_name}"
|
128
|
+
event["cpee:state"] = content['state'] if content['state']
|
129
|
+
event["cpee:description"] = content['dslx'] if content['dslx']
|
130
|
+
unless parameters["arguments"]&.nil?
|
131
|
+
event["data"] = parameters["arguments"]
|
132
|
+
end if parameters
|
133
|
+
if content['changed']&.any?
|
134
|
+
event["data"] = content['values'].map do |k,v|
|
135
|
+
{ 'name' => k, 'value' => v }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
if receiving && !receiving.empty?
|
139
|
+
fname = File.join(log_dir,instance + '_' + event["id:id"] + '.probe')
|
140
|
+
dname = File.join(log_dir,instance + '.data.json')
|
141
|
+
|
142
|
+
if File.exists?(fname)
|
143
|
+
te = event.dup
|
144
|
+
te['stream:sensorstream'] = []
|
145
|
+
|
146
|
+
rs = WEEL::ReadStructure.new(File.exists?(dname) ? JSON::load(File::open(dname)) : {},{},{})
|
147
|
+
XML::Smart::open_unprotected(fname) do |doc|
|
148
|
+
doc.register_namespace 'd', 'http://cpee.org/ns/description/1.0'
|
149
|
+
doc.find('//d:probe').each do |p|
|
150
|
+
tid = p.find('string(d:id)')
|
151
|
+
tso = p.find('string(d:source)')
|
152
|
+
if p.find('d:extractor_type[.="extrinsic"]')
|
153
|
+
val = CPEE::Logging::extract_sensor(rs,p.find('string(d:extractor_code)'),receiving) rescue nil
|
154
|
+
if val.is_a? Array
|
155
|
+
val.each do |e|
|
156
|
+
if e.is_a? StreamPoint
|
157
|
+
e.source ||= tso
|
158
|
+
te['stream:sensorstream'] << e.to_h(tid)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
else
|
162
|
+
tp = StreamPoint.new
|
163
|
+
tp.source = tso
|
164
|
+
tp.value = val
|
165
|
+
te['stream:sensorstream'] << tp.to_h(tid)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
te["cpee:lifecycle:transition"] = "sensor/stream"
|
171
|
+
File.open(File.join(log_dir,instance+'.xes.yaml'),'a') do |f|
|
172
|
+
f << {'event' => te}.to_yaml
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
event["raw"] = receiving
|
177
|
+
end
|
178
|
+
event["time:timestamp"]= event['cpee:timestamp'] || Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z")
|
179
|
+
File.open(File.join(log_dir,instance+'.xes.yaml'),'a') do |f|
|
180
|
+
f << {'event' => event}.to_yaml
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpee-logging-xes-yaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juergen eTM Mangler
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: tools
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-10-
|
12
|
+
date: 2022-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: riddl
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/cpee-logging-xes-yaml/logging.rb
|
76
76
|
- lib/cpee-logging-xes-yaml/logging.xml
|
77
77
|
- lib/cpee-logging-xes-yaml/template.xes_yaml
|
78
|
+
- lib/cpee-logging-xes-yaml/tools.rb
|
78
79
|
- server/log
|
79
80
|
- tools/cpee-logging-xes-yaml
|
80
81
|
homepage: http://cpee.org/
|