It is 2-3 files, 1 is the script, 2 is the config file and 3rd is the secrets file if you want. I have it setup as a CRON job to run every 12 hours, I haven't been running it long enough to know if that's a good interval or not but I haven't missed any linked monitor events since i've been running it.
Since it uses pyzm it needs to be run on your ZM or mlapi host, I will update it to use regular requests as well so it can be run on any system with python 3+. I just wanted to get this out there for people so they stop missing events because I keep seeing this issue pop up all over the place.
You call the script /path/to/script/linked_reset.py --config /path/to/config_file.ini and it will output to the console so testing is easy.
First it finds all your monitors, then searches for linked monitors. Meaning the monitor that sends the trigger to the Nodect linked monitor also gets restarted. Example: mon #1 is Nodect and is linked to mon #2, mon#2 is Mocord. Run the script and it sets both monitors to None, waits 5 seconds and then turns them back to Nodect and Mocord (or whatever function they were before the restart).
script-> https://github.com/baudneo/zmeventnotif ... d_reset.py
config -> https://github.com/baudneo/zmeventnotif ... d_conf.ini
Don't forget to chmod +x linked_reset.py, change secrets=./secrets.ini to point to your secrets file or just fill out the options right in the config file and comment (#) out the secrets= line.
Let me know if anything isn't working.
output ->
Code: Select all
>/home/tyler/PycharmProjects/linked_reset.py -c /home/tyler/PycharmProjects/linked_config.ini
07/27/21 21:33:22.400201 CNSL[DBG1] linked_reset:34->[util: secret filename: /home/tyler/PycharmProjects/secrets.ini ]
07/27/21 21:33:22.4012 CNSL[DBG2] linked_reset:69->[util: secret token found in config: !ZMUSER ]
07/27/21 21:33:22.401733 CNSL[DBG2] linked_reset:69->[util: secret token found in config: !ZMPASS ]
07/27/21 21:33:22.402258 CNSL[DBG2] linked_reset:69->[util: secret token found in config: !PORTAL ]
07/27/21 21:33:22.402781 CNSL[DBG2] linked_reset:69->[util: secret token found in config: !API_PORTAL ]
07/27/21 21:33:22.403399 CNSL[DBG2] linked_reset:94->[util: parameter substitution ({{ <var> }}) ]
07/27/21 21:33:22.404562 CNSL[DBG2] api:83->[pyzm:api: SSL certificate verification disabled (encryption still works, vuln to spoofing) ]
07/27/21 21:33:22.405239 CNSL[DBG1] api:199->[pyzm:api: no token found, using user/pass to login ]
07/27/21 21:33:22.554511 CNSL[DBG2] api:228->[pyzm:api: detected API ver 2.0+, using token system ]
07/27/21 21:33:22.555318 CNSL[DBG1] api:236->[pyzm:api: access token expires on: 2021-07-28 03:33:22.554619 (21600s) ]
07/27/21 21:33:22.556041 CNSL[DBG1] api:243->[pyzm:api: refresh token expires on: 2021-07-28 21:33:22.555373 (86400s) ]
07/27/21 21:33:22.556994 CNSL[DBG2] Monitors:22->[Retrieving monitors via API ]
07/27/21 21:33:22.557867 CNSL[DBG2] api:303->[pyzm:api:make_req: 'get'->https://<hidden>/zm/api/monitors.json query={'token': 'eyJ0eXAiOiJKV1QiLCJhbGciO...'} ]
mid: 1 name: Front function: Nodect linked monitors: ['2'] enabled:True
mid: 2 name: Front - Sub function: Mocord linked monitors: None enabled:True
mid: 3 name: Back Alley function: Modect linked monitors: None enabled:True
mid: 4 name: Back Yard function: Monitor linked monitors: None enabled:True
has_linked = [1] ---- linked_from = [2] ---- tot_mons = [2, 1] --- tot = {1: 'Nodect', 2: 'Mocord'}
07/27/21 21:33:22.577198 CNSL[DBG2] api:303->[pyzm:api:make_req: 'post'->https://<hidden>/zm/api/monitors/1.json payload={'Monitor[Function]': 'None'} query={'token': 'eyJ0eXAiOiJKV1QiLCJhbGciO...'} ]
07/27/21 21:33:22.831785 CNSL[DBG2] api:303->[pyzm:api:make_req: 'post'->https://<hidden>/zm/api/monitors/2.json payload={'Monitor[Function]': 'None'} query={'token': 'eyJ0eXAiOiJKV1QiLCJhbGciO...'} ]
sleeping for 5 seconds and then returning monitors to previous function
07/27/21 21:33:28.093062 CNSL[DBG2] api:303->[pyzm:api:make_req: 'post'->https://<hidden>/zm/api/monitors/1.json payload={'Monitor[Function]': 'Nodect'} query={'token': 'eyJ0eXAiOiJKV1QiLCJhbGciO...'} ]
07/27/21 21:33:28.537681 CNSL[DBG2] api:303->[pyzm:api:make_req: 'post'->https://<hidden>/zm/api/monitors/2.json payload={'Monitor[Function]': 'Mocord'} query={'token': 'eyJ0eXAiOiJKV1QiLCJhbGciO...'} ]