+ if (link(__alogfile, ALERTS_DAILY) == -1) {
+ ErrorExit(LINK_ERROR, ARGV0, __alogfile, ALERTS_DAILY, errno, strerror(errno));
+ }
+
+ if (Config.jsonout_output) {
+
+ if (_jflog) {
+ if (ftell(_jflog) == 0) {
+ unlink(__jlogfile);
+ }
+ fclose(_jflog);
+ _jflog = NULL;
+ }
+
+ snprintf(__jlogfile, OS_FLSIZE, "%s/%d/", ALERTS, lf->year);
+ if (IsDir(__jlogfile) == -1)
+ if (mkdir(__jlogfile, 0770) == -1) {
+ ErrorExit(MKDIR_ERROR, ARGV0, __jlogfile, errno, strerror(errno));
+ }
+
+ snprintf(__jlogfile, OS_FLSIZE, "%s/%d/%s", ALERTS, lf->year, lf->mon);
+
+ if (IsDir(__jlogfile) == -1)
+ if (mkdir(__jlogfile, 0770) == -1) {
+ ErrorExit(MKDIR_ERROR, ARGV0, __jlogfile, errno, strerror(errno));
+ }
+
+
+
+ /* Create the json logfile name */
+ snprintf(__jlogfile, OS_FLSIZE, "%s/%d/%s/ossec-%s-%02d.json",
+ ALERTS,
+ lf->year,
+ lf->mon,
+ "alerts",
+ lf->day);
+
+ _jflog = fopen(__jlogfile, "a");
+
+ if (!_jflog) {
+ ErrorExit("%s: Error opening logfile: '%s'", ARGV0, __jlogfile);
+ }
+
+ /* Create a symlink */
+ unlink(ALERTSJSON_DAILY);
+
+ if (link(__jlogfile, ALERTSJSON_DAILY) == -1) {
+ ErrorExit(LINK_ERROR, ARGV0, __jlogfile, ALERTSJSON_DAILY, errno, strerror(errno));
+ }
+
+ }