Skip to content

Commit acfa824

Browse files
authored
Add a switch to route_check to control whether write log to syslog (sonic-net#1215)
route_check.py will report an ERROR in syslog if route mismatch is found, which is out control of monit config file. This commit add an option (-s) to control whether error will be reported in syslog. **- How to verify it** The update is verified on Arista-7260. 1. Add a static route whose nexthop is not reachable. ``` ip route add 1.1.1.1 via 192.168.1.101 ``` 2. Run ```route_check.py```, and error msg is only printed on stdout. Nothing is writen to syslog 3. Run ```route_check.py -s```. and error msg is writen to both stdout and syslog 4. Wait for 15 minutes, and confirm that monit will report the error ``` Nov 4 09:30:36.917367 str-7260cx3-acs-2 ERR monit[631]: 'routeCheck' status failed (255) -- results: { {#12 "missed_ROUTE_TABLE_routes": [#12 "1.1.1.1/32"#12 ]#12} }#12 Failed. Look at reported mismatches above ``` Signed-off-by: bingwang <[email protected]>
1 parent e3d3d92 commit acfa824

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

scripts/route_check.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ def __str__(self):
3030

3131

3232
report_level = syslog.LOG_ERR
33+
write_to_syslog = False
3334

34-
35-
def set_level(lvl):
35+
def set_level(lvl, log_to_syslog):
3636
global report_level
37+
global write_to_syslog
3738

39+
write_to_syslog = log_to_syslog
3840
if (lvl == Level.INFO):
3941
report_level = syslog.LOG_INFO
4042

@@ -48,7 +50,8 @@ def print_message(lvl, *args):
4850
for arg in args:
4951
msg += " " + str(arg)
5052
print(msg)
51-
syslog.syslog(lvl, msg)
53+
if write_to_syslog:
54+
syslog.syslog(lvl, msg)
5255

5356

5457
def add_prefix(ip):
@@ -167,7 +170,7 @@ def filter_out_local_interfaces(keys):
167170

168171
db = ConfigDBConnector()
169172
db.db_connect('APPL_DB')
170-
173+
171174
for k in keys:
172175
e = db.get_entry('ROUTE_TABLE', k)
173176
if not e:
@@ -240,9 +243,10 @@ def main(argv):
240243
parser=argparse.ArgumentParser(description="Verify routes between APPL-DB & ASIC-DB are in sync")
241244
parser.add_argument('-m', "--mode", type=Level, choices=list(Level), default='ERR')
242245
parser.add_argument("-i", "--interval", type=int, default=0, help="Scan interval in seconds")
246+
parser.add_argument("-s", "--log_to_syslog", action="store_true", default=False, help="Write message to syslog")
243247
args = parser.parse_args()
244248

245-
set_level(args.mode)
249+
set_level(args.mode, args.log_to_syslog)
246250

247251
if args.interval:
248252
if (args.interval < MIN_SCAN_INTERVAL):

0 commit comments

Comments
 (0)