Commit 5587749f authored by Ophélie Gagnard's avatar Ophélie Gagnard

Modify the json string to that directories' path and with '/'.

parent 8eb14c23
...@@ -40,12 +40,7 @@ cdef cypclass Node activable: ...@@ -40,12 +40,7 @@ cdef cypclass Node activable:
pass pass
void format_node(self): void format_node(self):
self.formatted = sprintf("""\ self.formatted = sprintf("""{"path": "%s", "stat": %s}\n""",
{
"path": "%s",
"stat": %s
},
""",
self.path, self.path,
self.st.to_json(), self.st.to_json(),
) )
...@@ -117,6 +112,12 @@ cdef cypclass DirNode(Node): ...@@ -117,6 +112,12 @@ cdef cypclass DirNode(Node):
for active_child in self.children: for active_child in self.children:
active_child.build_node(NULL, dev_whitelist, ignore_paths) active_child.build_node(NULL, dev_whitelist, ignore_paths)
void format_node(self):
self.formatted = sprintf("""{"path": "%s/", "stat": %s}\n""",
self.path,
self.st.to_json(),
)
void write_node(self, FILE * stream): void write_node(self, FILE * stream):
fwrite(self.formatted.data(), 1, self.formatted.size(), stream) fwrite(self.formatted.data(), 1, self.formatted.size(), stream)
while self.children.__len__() > 0: while self.children.__len__() > 0:
...@@ -192,18 +193,7 @@ cdef cypclass FileNode(Node): ...@@ -192,18 +193,7 @@ cdef cypclass FileNode(Node):
if self.error: if self.error:
Node.format_node(self) Node.format_node(self)
else: else:
self.formatted = sprintf("""\ self.formatted = sprintf("""{"path": "%s", "stat": %s, "hash": {"md5": "%s", "sha1": "%s", "sha256": "%s", "sha512": "%s"}}\n""",
{
"path": "%s",
"stat": %s,
"hash": {
"md5": "%s",
"sha1": "%s",
"sha256": "%s",
"sha512": "%s"
}
},
""",
self.path, self.path,
self.st.to_json(), self.st.to_json(),
self.md5_data, self.md5_data,
...@@ -232,13 +222,7 @@ cdef cypclass SymlinkNode(Node): ...@@ -232,13 +222,7 @@ cdef cypclass SymlinkNode(Node):
if self.error: if self.error:
Node.format_node(self) Node.format_node(self)
else: else:
self.formatted = sprintf("""\ self.formatted = sprintf("""{"path": "%s", "stat": %s, "target": "%s"}\n""",
{
"path": "%s",
"stat": %s,
"target": "%s"
},
""",
self.path, self.path,
self.st.to_json(), self.st.to_json(),
self.target, self.target,
...@@ -269,7 +253,6 @@ cdef int start(const char *path) nogil: ...@@ -269,7 +253,6 @@ cdef int start(const char *path) nogil:
err = execlp("flb/fluent-bit", program_name, arg1, arg2, arg3, arg4, 0) err = execlp("flb/fluent-bit", program_name, arg1, arg2, arg3, arg4, 0)
fprintf(stderr, "ERROR with execlp() in CHILD: %d\n", err) fprintf(stderr, "ERROR with execlp() in CHILD: %d\n", err)
else: # PARENT else: # PARENT
printf("WELCOME TO PARENT\n\n") # DEBUG printf("WELCOME TO PARENT\n\n") # DEBUG
sleep(2) # TODO error handling ; check if a wait can be made to wait for the child to perform execlp() (instead of the sleep) sleep(2) # TODO error handling ; check if a wait can be made to wait for the child to perform execlp() (instead of the sleep)
...@@ -307,26 +290,32 @@ cdef int start(const char *path) nogil: ...@@ -307,26 +290,32 @@ cdef int start(const char *path) nogil:
fflush(stderr) # DEBUG fflush(stderr) # DEBUG
active_node = activate(consume node) active_node = activate(consume node)
fprintf(stderr, 'test 003\n') # DEBUG
fflush(stderr) # DEBUG
active_node.build_node(NULL, consume dev_whitelist, consume ignore_paths) active_node.build_node(NULL, consume dev_whitelist, consume ignore_paths)
fprintf(stderr, 'test 004\n') # DEBUG
fflush(stderr) # DEBUG
scheduler.finish() scheduler.finish()
fprintf(stderr, 'test 005\n') # DEBUG
fflush(stderr) # DEBUG
node = consume active_node node = consume active_node
#""" # DEBUG #""" # DEBUG
result = fopen('/var/log/metadata_collect.log', 'w') result = fopen('/var/log/metadata_collect.log', 'w')
if result is NULL: if result is NULL:
fprintf(stderr, 'Error creating the log file.\n') # DEBUG
fflush(stderr)
return -1 return -1
printf("WRITE_NOTE STAGE\n\n") # DEBUG fprintf(stderr, 'Log opened successfully.\n') # DEBUG
fprintf(stderr, "WRITE_NOTE STAGE\n\n") # DEBUG
fscanf(address_path, "%s", ip_address) fscanf(address_path, "%s", ip_address)
fclose(address_path) fclose(address_path)
fprintf(result, '[\n') fprintf(result, '{"mac_address": "%s"}\n', ip_address)
fprintf(result, '"%s",\n', ip_address)
node.write_node(result) node.write_node(result)
fprintf(result, ' {}\n]\n') fprintf(result, '{}\n')
fprintf(result, 'fluentbit_end\n') fprintf(result, 'fluentbit_end\n')
fclose(result) fclose(result)
...@@ -337,7 +326,7 @@ cdef int start(const char *path) nogil: ...@@ -337,7 +326,7 @@ cdef int start(const char *path) nogil:
wait_error = wait(NULL) # TODO improve this call (error handling, etc.) wait_error = wait(NULL) # TODO improve this call (error handling, etc.)
#wait_error = waitpid(child_pid, NULL, 1) # TODO improve this call (error handling, etc.) #wait_error = waitpid(child_pid, NULL, 1) # TODO improve this call (error handling, etc.)
fprintf(stderr, "WAITING ENDS\n\n") fprintf(stderr, "WAITING ENDS\n\n")
fflush(stderr) # DEBUG
return 0 return 0
......
...@@ -108,24 +108,7 @@ cdef cypclass Stat: ...@@ -108,24 +108,7 @@ cdef cypclass Stat:
return S_ISDIR(self.st_data.st_mode) return S_ISDIR(self.st_data.st_mode)
string to_json(self): string to_json(self):
return sprintf("""{ return sprintf("""{"st_dev": %lu, "st_ino": %lu, "st_mode": %lu, "st_nlink": %lu, "st_uid": %d, "st_gid": %d, "st_rdev": %lu, "st_size": %ld, "st_blksize": %ld, "st_blocks": %ld, "st_atime": %ld, "st_mtime": %ld, "st_ctime": %ld, "st_atime_ns": %ld, "st_mtime_ns": %ld, "st_ctime_ns": %ld}""",
"st_dev": %lu,
"st_ino": %lu,
"st_mode": %lu,
"st_nlink": %lu,
"st_uid": %d,
"st_gid": %d,
"st_rdev": %lu,
"st_size": %ld,
"st_blksize": %ld,
"st_blocks": %ld,
"st_atime": %ld,
"st_mtime": %ld,
"st_ctime": %ld,
"st_atime_ns": %ld,
"st_mtime_ns": %ld,
"st_ctime_ns": %ld
}""",
self.st_data.st_dev, self.st_data.st_dev,
self.st_data.st_ino, self.st_data.st_ino,
self.st_data.st_mode, self.st_data.st_mode,
......
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