Skip to content

Commit

Permalink
Merge pull request #25 from ndam-bluecat/master
Browse files Browse the repository at this point in the history
Fix Issue Syslog-Mon Alarm Cannot Be Clear After Reboot
  • Loading branch information
carynn-nguyen authored Dec 30, 2022
2 parents 29c2b34 + dd7ad3e commit 48e9680
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions services/docker.syslog.service
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ExecStart=/usr/bin/docker run --rm \
--log-driver=none \
-v /var/log/syslog_monitoring/:/var/log/mon-app/ \
-v /opt/syslog_monitoring/Config/:/etc/syslog-ng/syslog_monitoring/Config/ \
-v /opt/syslog_monitoring/alarm_state/:/etc/syslog-ng/syslog_monitoring/alarm_state/ \
-v /var/lib/snmp/:/var/lib/snmp/ \
$IMAGE_NAME
[Install]
Expand Down
13 changes: 9 additions & 4 deletions syslog_monitoring/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import json
from config import *
from Alarm import alarm_management, common

basedir = os.path.dirname(os.path.abspath(__file__))
alarm_state_dir = os.path.join(basedir, "alarm_state")
is_exist = os.path.exists(alarm_state_dir)
if not is_exist:
os.mkdir(alarm_state_dir)


class Monitoring(object):
Expand All @@ -38,8 +43,8 @@ def open(self):
logger.info("Monitoring:{0}".format("Open"))
self._is_opened = True

state_file = os.path.join(basedir, "current_state")
forceclear_file = os.path.join(basedir, "forceclear")
state_file = os.path.join(alarm_state_dir, "current_state")
forceclear_file = os.path.join(alarm_state_dir, "forceclear")
state_data = common.read_file(state_file)
if state_data:
state = json.loads(state_data)
Expand All @@ -60,7 +65,7 @@ def open(self):
def close(self):
"""Close the connection to the target service"""
logger.info("Monitoring:{0}".format("Close"))
state_file = os.path.join(basedir, "current_state")
state_file = os.path.join(alarm_state_dir, "current_state")
state = json.dumps(alarm_management.key_pair)
with open(state_file, "w+") as f:
logger.info("Create state file: {}".format(state_file))
Expand Down Expand Up @@ -92,7 +97,7 @@ def send(self, msg):
if cond is None or keypair is None or err_type is None:
return True
if cond == "forceclear":
forceclear = os.path.join(basedir, "forceclear")
forceclear = os.path.join(alarm_state_dir, "forceclear")
data = "{0}|{1}|{2}|{3}|{4}|{5}".format(cond, msg["LEVEL"], keypair, msg["MESSAGE"], err_type, host)
with open(forceclear, "w+") as forceclear_file:
logger.info("Create forceclear file: {}".format(forceclear))
Expand Down
13 changes: 12 additions & 1 deletion syslog_monitoring/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/usr/bin/env bash

kill_syslog_ng() {
echo "Start kill syslog-ng ..."
pkill syslog-ng
sleep 10
}
trap "echo SIGINT; kill_syslog_ng; exit" SIGINT
trap "echo SIGTERM; kill_syslog_ng; exit" SIGTERM
echo Starting script

echo "Restart cron service if it not running ..."

if service cron status | grep 'is running'
Expand All @@ -11,4 +20,6 @@ fi

echo "Run syslog-ng in foreground ..."

syslog-ng --process-mode=foreground --no-caps
syslog-ng --process-mode=foreground --no-caps &

wait -n

0 comments on commit 48e9680

Please sign in to comment.