Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
metadata-collect-agent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
metadata-collect-agent
Commits
46de40d4
Commit
46de40d4
authored
Jun 04, 2021
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrtie to file
parent
3a45181c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
75 deletions
+6
-75
src/main.rs
src/main.rs
+6
-75
No files found.
src/main.rs
View file @
46de40d4
...
...
@@ -225,75 +225,8 @@ fn upload_to_erp5<R: Read + Send + 'static>(
password
:
&
str
,
reference
:
&
str
,
)
->
Result
<
()
>
{
let
mut
headers
=
header
::
HeaderMap
::
new
();
headers
.insert
(
header
::
AUTHORIZATION
,
header
::
HeaderValue
::
from_str
(
&
format!
(
"Basic {}"
,
&
base64
::
encode
(
&
format!
(
"{}:{}"
,
username
,
password
))
))
?
,
);
let
client
=
Client
::
builder
()
.redirect
(
redirect
::
Policy
::
none
())
.default_headers
(
headers
)
.build
()
?
;
let
resp
=
client
.get
(
&
format!
(
"{}/portal_contributions/newContent"
,
base_url
))
.query
(
&
[
(
"portal_type"
,
"Computer Metadata Snapshot"
),
(
"filename"
,
&
format!
(
"{}.metadata"
,
&
reference
)),
(
"container_path"
,
"computer_metadata_snapshot_module"
),
(
"data"
,
""
),
])
.send
()
?
;
// workaround for ERP5 disappearing documents race condition bug
thread
::
sleep
(
Duration
::
from_secs
(
3
));
let
doc_url
:
reqwest
::
Url
=
resp
.headers
()
.get
(
"X-Location"
)
.ok_or_else
(||
anyhow
::
format_err!
(
"X-Location must exist"
))
?
.to_str
()
?
.parse
()
?
;
let
_
resp
=
client
.post
(
doc_url
.to_owned
())
.multipart
(
multipart
::
Form
::
new
()
.text
(
"form_id"
,
"File_view"
)
.text
(
"object_path"
,
doc_url
.path
()
.to_owned
())
.text
(
"field_my_reference"
,
reference
.to_owned
())
.part
(
"field_my_file"
,
Part
::
reader_with_length
(
reader
,
size
)
.file_name
(
format!
(
"{}.metadata"
,
&
reference
)),
)
.text
(
"Base_edit:method"
,
""
),
)
.send
()
?
;
// workaround for ERP5 disappearing documents race condition bug
thread
::
sleep
(
Duration
::
from_secs
(
3
));
let
mut
params
=
HashMap
::
new
();
params
.insert
(
"dialog_id"
,
"Base_viewWorkflowActionDialog"
);
params
.insert
(
"dialog_method"
,
"Workflow_statusModify"
);
params
.insert
(
"form_id"
,
"File_view"
);
params
.insert
(
"object_path"
,
doc_url
.path
());
params
.insert
(
"field_your_comment"
,
""
);
params
.insert
(
"field_your_workflow_action"
,
"share_action"
);
params
.insert
(
"Base_callDialogMethod:method"
,
""
);
let
_
resp
=
client
.post
(
doc_url
.to_owned
())
.form
(
&
params
)
.send
()
?
;
// workaround for ERP5 disappearing documents race condition bug
thread
::
sleep
(
Duration
::
from_secs
(
3
));
Ok
(())
Part
::
reader_with_length
(
reader
,
size
)
.file_name
(
format!
(
"/var/log/metadata_collect.log"
));
Ok
(())
}
fn
main
()
->
Result
<
()
>
{
...
...
@@ -331,6 +264,8 @@ fn main() -> Result<()> {
.unwrap_or
(
clap
::
Values
::
default
())
.map
(
PathBuf
::
from
)
.collect
();
let
mut
file
=
OpenOptions
::
new
()
.write
(
true
)
.append
(
true
)
.create
(
true
)
.open
(
"/var/log/metadata_collect.log"
)
.unwrap
();
let
mut
child
=
Command
::
new
(
"/sbin/fluent-bit"
)
.args
(
&
[
"-e"
,
"/etc/out_gstdout.so"
,
"-c"
,
"/etc/flb.conf"
])
.spawn
()
.unwrap
();
let
disk_partitions
=
psutil
::
disk
::
partitions_physical
()
?
;
...
...
@@ -352,7 +287,6 @@ fn main() -> Result<()> {
let
packed
=
serde_json
::
to_vec
(
&
snapshot
)
?
;
let
packed_size
=
packed
.len
()
as
u64
;
let
mut
file
=
OpenOptions
::
new
()
.write
(
true
)
.append
(
true
)
.create
(
true
)
.open
(
"/var/log/metadata_collect.log"
)
.unwrap
();
upload_to_erp5
(
Cursor
::
new
(
packed
),
packed_size
,
...
...
@@ -362,11 +296,8 @@ fn main() -> Result<()> {
m
.value_of
(
"erp5-file-reference"
)
.unwrap
(),
)
?
;
let
mut
child
=
Command
::
new
(
"/sbin/fluent-bit"
)
.args
(
&
[
"-e"
,
"/etc/out_gstdout.so"
,
"-c"
,
"/etc/flb.conf"
])
.spawn
()
.unwrap
();
thread
::
sleep
(
Duration
::
from_secs
(
60
));
writeln!
(
file
,
"[200202: 2002020]"
);
writeln!
(
file
,
"[2020222:20390294]"
);
writeln!
(
file
,
"[200202: end]"
);
writeln!
(
file
,
"[2020222: end]"
);
let
_
result
=
child
.wait
()
.unwrap
();
Ok
(())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment