Skip to content

Commit

Permalink
Add a switch to route_check to control whether write log to syslog (s…
Browse files Browse the repository at this point in the history
…onic-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 <bingwang@microsoft.com>
  • Loading branch information
bingwang-ms authored Nov 4, 2020
1 parent e3d3d92 commit acfa824
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ def __str__(self):


report_level = syslog.LOG_ERR
write_to_syslog = False


def set_level(lvl):
def set_level(lvl, log_to_syslog):
global report_level
global write_to_syslog

write_to_syslog = log_to_syslog
if (lvl == Level.INFO):
report_level = syslog.LOG_INFO

Expand All @@ -48,7 +50,8 @@ def print_message(lvl, *args):
for arg in args:
msg += " " + str(arg)
print(msg)
syslog.syslog(lvl, msg)
if write_to_syslog:
syslog.syslog(lvl, msg)


def add_prefix(ip):
Expand Down Expand Up @@ -167,7 +170,7 @@ def filter_out_local_interfaces(keys):

db = ConfigDBConnector()
db.db_connect('APPL_DB')

for k in keys:
e = db.get_entry('ROUTE_TABLE', k)
if not e:
Expand Down Expand Up @@ -240,9 +243,10 @@ def main(argv):
parser=argparse.ArgumentParser(description="Verify routes between APPL-DB & ASIC-DB are in sync")
parser.add_argument('-m', "--mode", type=Level, choices=list(Level), default='ERR')
parser.add_argument("-i", "--interval", type=int, default=0, help="Scan interval in seconds")
parser.add_argument("-s", "--log_to_syslog", action="store_true", default=False, help="Write message to syslog")
args = parser.parse_args()

set_level(args.mode)
set_level(args.mode, args.log_to_syslog)

if args.interval:
if (args.interval < MIN_SCAN_INTERVAL):
Expand Down

0 comments on commit acfa824

Please sign in to comment.