Commit 46de40d4 authored by Xiaowu Zhang's avatar Xiaowu Zhang

wrtie to file

parent 3a45181c
......@@ -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(())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment