Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON compliance and agent_control #1600

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 0 additions & 127 deletions etc/preloaded-vars.conf.example

This file was deleted.

4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,8 @@ list_agents: util/list_agents.o ${ossec_libs} ${ZLIB_LIB}
verify-agent-conf: util/verify-agent-conf.o ${ossec_libs} ${ZLIB_LIB}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${ZLIB_INCLUDE} $^ ${OSSEC_LDFLAGS} -o $@

agent_control: util/agent_control.o addagent/validate.o ${ossec_libs} ${ZLIB_LIB}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${ZLIB_INCLUDE} $^ ${OSSEC_LDFLAGS} -o $@
agent_control: util/agent_control.o addagent/validate.o ${ossec_libs} ${ZLIB_LIB} ${JSON_LIB}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${ZLIB_INCLUDE} ${JSON_INCLUDE} $^ -lm ${OSSEC_LDFLAGS} -o $@

syscheck_control: util/syscheck_control.o addagent/validate.o ${ossec_libs} ${ZLIB_LIB}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${ZLIB_INCLUDE} $^ ${OSSEC_LDFLAGS} -o $@
Expand Down
4 changes: 2 additions & 2 deletions src/addagent/manage_agents.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ int remove_agent()



if (!print_agents(0, 0, 0)) {
if (!print_agents(0, 0, 0, 0)) {
printf(NO_AGENT);
return (0);
}
Expand Down Expand Up @@ -412,7 +412,7 @@ int remove_agent()

int list_agents(int cmdlist)
{
if (!print_agents(0, 0, 0)) {
if (!print_agents(0, 0, 0, 0)) {
printf(NO_AGENT);
}

Expand Down
2 changes: 1 addition & 1 deletion src/addagent/manage_agents.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ double OS_AgentAntiquity(const char *id);
void FormatID(char *id);

/* Print available agents */
int print_agents(int print_status, int active_only, int csv_output);
int print_agents(int print_status, int active_only, int csv_output, int json_output);
int list_agents(int cmdlist);

/* Clear a line */
Expand Down
2 changes: 1 addition & 1 deletion src/addagent/manage_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int k_extract(const char *cmdextract)
exit(1);
}
} else {
if (!print_agents(0, 0, 0)) {
if (!print_agents(0, 0, 0, 0)) {
printf(NO_AGENT);
printf(PRESS_ENTER);
read_from_user();
Expand Down
14 changes: 7 additions & 7 deletions src/addagent/validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ double OS_AgentAntiquity(const char *id)
}

/* Print available agents */
int print_agents(int print_status, int active_only, int csv_output)
int print_agents(int print_status, int active_only, int csv_output, int json_output)
{
int total = 0;
FILE *fp;
Expand Down Expand Up @@ -520,11 +520,11 @@ int print_agents(int print_status, int active_only, int csv_output)
}

if (csv_output) {
printf("%s,%s,%s,%s,\n", line_read, name, ip,
print_agent_status(agt_status));
} else {
printf(PRINT_AGENT_STATUS, line_read, name, ip,
print_agent_status(agt_status));
printf("%s,%s,%s,%s,\n", line_read, name, ip, print_agent_status(agt_status));
}else if (json_output) {
printf(", { \"ID\" : \"%s\", \"Name\" : \"%s\", \"IP\": \"%s\", \"Status\" : \"%s\" }",line_read, name, ip, print_agent_status(agt_status));
} else {
printf(PRINT_AGENT_STATUS, line_read, name, ip, print_agent_status(agt_status));
}
} else {
printf(PRINT_AGENT, line_read, name, ip);
Expand All @@ -540,7 +540,7 @@ int print_agents(int print_status, int active_only, int csv_output)
DIR *dirp;
struct dirent *dp;

if (!csv_output) {
if (!csv_output && !json_output) {
printf("\nList of agentless devices:\n");
}

Expand Down
31 changes: 29 additions & 2 deletions src/analysisd/alerts/getloglocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ FILE *_eflog;
FILE *_aflog;
FILE *_fflog;
FILE *_jflog;
FILE *_ejflog;

/* Global variables */
static int __crt_day;
static char __elogfile[OS_FLSIZE + 1];
static char __alogfile[OS_FLSIZE + 1];
static char __flogfile[OS_FLSIZE + 1];
static char __jlogfile[OS_FLSIZE + 1];

static char __ejlogfile[OS_FLSIZE + 1];

void OS_InitLog()
{
Expand All @@ -37,11 +38,13 @@ void OS_InitLog()
memset(__elogfile, '\0', OS_FLSIZE + 1);
memset(__flogfile, '\0', OS_FLSIZE + 1);
memset(__jlogfile, '\0', OS_FLSIZE + 1);
memset(__ejlogfile, '\0', OS_FLSIZE + 1);

_eflog = NULL;
_aflog = NULL;
_fflog = NULL;
_jflog = NULL;
_ejflog = NULL;

/* Set the umask */
umask(0027);
Expand All @@ -53,7 +56,8 @@ int OS_GetLogLocation(const Eventinfo *lf)
* Check if the year directory is there
* If not, create it. Same for the month directory.
*/



/* For the events */
if (_eflog) {
if (ftell(_eflog) == 0) {
Expand Down Expand Up @@ -95,7 +99,30 @@ int OS_GetLogLocation(const Eventinfo *lf)
if (link(__elogfile, EVENTS_DAILY) == -1) {
ErrorExit(LINK_ERROR, ARGV0, __elogfile, EVENTS_DAILY, errno, strerror(errno));
}
/* For the events in JSON */
if (Config.jsonout_output) {
/* Create the json archives logfile name */
snprintf(__ejlogfile, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.json",
EVENTS,
lf->year,
lf->mon,
"archive",
lf->day);

_ejflog = fopen(__ejlogfile, "a");

if (!_ejflog) {
ErrorExit("%s: Error opening logfile: '%s'", ARGV0, __ejlogfile);
}

/* Create a symlink */
unlink(EVENTSJSON_DAILY);

if (link(__ejlogfile, EVENTSJSON_DAILY) == -1) {
ErrorExit(LINK_ERROR, ARGV0, __ejlogfile, EVENTSJSON_DAILY, errno, strerror(errno));
}
}

/* For the alerts logs */
if (_aflog) {
if (ftell(_aflog) == 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/analysisd/alerts/getloglocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ int OS_GetLogLocation(const Eventinfo *lf);

/* Global declarations */
extern FILE *_eflog;
extern FILE *_ejflog;
extern FILE *_aflog;
extern FILE *_fflog;
extern FILE *_jflog;
extern FILE *_ejflog;

#endif /* __GETLL_H */

1 change: 1 addition & 0 deletions src/analysisd/analysisd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ void OS_ReadMSG_analysisd(int m_queue)
/* If configured to log all, do it */
if (Config.logall) {
OS_Store(lf);
jsonout_output_archive(lf);
}

CLMEM:
Expand Down
Loading