Kaynağa Gözat

fix post merge (#138)

* fix post merge (#138)
AlteredCoder 5 yıl önce
ebeveyn
işleme
0864f13cb8
3 değiştirilmiş dosya ile 20 ekleme ve 3 silme
  1. 17 1
      cmd/crowdsec-cli/backup-restore.go
  2. 1 1
      pkg/database/commit.go
  3. 2 1
      wizard.sh

+ 17 - 1
cmd/crowdsec-cli/backup-restore.go

@@ -112,7 +112,16 @@ as well attempts to restore api credentials after verifying the existing ones ar
 finally restores the acquis.yaml file*/
 func restoreFromDirectory(source string) error {
 	var err error
-	/*backup scenarios etc.*/
+
+	/*restore simulation configuration*/
+	backSimul := fmt.Sprintf("%s/simulation.yaml", source)
+	if _, err = os.Stat(backSimul); err == nil {
+		if err = copyFile(backSimul, config.SimulationCfgPath); err != nil {
+			return fmt.Errorf("failed copy %s to %s : %s", backSimul, config.SimulationCfgPath, err)
+		}
+	}
+
+	/*restore scenarios etc.*/
 	for _, itype := range cwhub.ItemTypes {
 		itemDirectory := fmt.Sprintf("%s/%s/", source, itype)
 		if _, err = os.Stat(itemDirectory); err != nil {
@@ -298,7 +307,14 @@ func backupToDirectory(target string) error {
 	/*
 		backup configurations :
 			- parers, scenarios, collections, postoverflows
+			- simulation configuration
 	*/
+	if config.SimulationCfgPath != "" {
+		backSimul := fmt.Sprintf("%s/simulation.yaml", target)
+		if err = copyFile(config.SimulationCfgPath, backSimul); err != nil {
+			return fmt.Errorf("failed copy %s to %s : %s", config.SimulationCfgPath, backSimul, err)
+		}
+	}
 
 	for _, itemType := range cwhub.ItemTypes {
 		clog := log.WithFields(log.Fields{

+ 1 - 1
pkg/database/commit.go

@@ -48,7 +48,7 @@ func (c *Context) CleanUpRecordsByAge() error {
 
 	//look for soft-deleted events that are OLDER than maxDurationRetention
 	ret := c.Db.Unscoped().Table("ban_applications").Where("deleted_at is not NULL").
-		Where(fmt.Sprintf("deleted_at > date('now','-%d minutes')", int(c.maxDurationRetention.Minutes()))).
+		Where("deleted_at > ?", time.Now().Add(-c.maxDurationRetention)).
 		Order("updated_at desc").Find(&sos)
 
 	if ret.Error != nil {

+ 2 - 1
wizard.sh

@@ -136,7 +136,7 @@ log_locations[nginx]='/var/log/nginx/*.log'
 log_locations[sshd]='/var/log/auth.log,/var/log/sshd.log,/var/log/secure'
 log_locations[rsyslog]='/var/log/syslog'
 log_locations[telnet]='/var/log/telnetd*.log'
-log_locations[mysql]='/var/log/mysqld*.log'
+log_locations[mysql]='/var/log/mysql/error.log'
 log_locations[smb]='/var/log/samba*.log'
 log_locations[linux]='/var/log/syslog,/var/log/kern.log,/var/log/messages'
 
@@ -299,6 +299,7 @@ install_crowdsec() {
     install -v -m 755 -D ./config/acquis.yaml "${CROWDSEC_CONFIG_PATH}" || exit
     install -v -m 755 -D ./config/profiles.yaml "${CROWDSEC_CONFIG_PATH}" || exit
     install -v -m 600 -D ./config/api.yaml "${CROWDSEC_CONFIG_PATH}" || exit
+    install -v -m 600 -D ./config/simulation.yaml "${CROWDSEC_CONFIG_PATH}" || exit
     mkdir -p ${PID_DIR} || exit
     PID=${PID_DIR} DATA=${CROWDSEC_DATA_DIR} CFG=${CROWDSEC_CONFIG_PATH} envsubst '$CFG $PID $DATA' < ./config/prod.yaml > ${CROWDSEC_CONFIG_PATH}"/default.yaml"   
     PID=${PID_DIR} DATA=${CROWDSEC_DATA_DIR} CFG=${CROWDSEC_CONFIG_PATH} envsubst '$CFG $PID $DATA' < ./config/user.yaml > ${CROWDSEC_CONFIG_PATH}"/user.yaml"