[Python & Dashboard API] Simple event log counter

gabtoub
Here to help

[Python & Dashboard API] Simple event log counter

Hello everyone, 

 

I'd like to share a project I made when I needed to get a simple count of DFS events on my wireless networks on a defined timespan (in days) , for a specific netID or the whole organization, for a specific type of device.

 

You can add into parameters the type of event you want to monitor (here for example : dfs_event)

 

gabtoub_0-1605463092976.png

 

You can get the script here : https://github.com/gabtoub/getMerakiEventCount/

Feel free to discuss or share your advices/remarks about this script,

 

Gabriel 

 

3 Replies 3
PhilipDAth
Kind of a big deal
Kind of a big deal

Great idea!

Greenberet
Head in the Cloud

Nice Idea.

 

I have a few comments about the implementation of the script:

 

  1. Use only one session object and pass it as parameter instead of the apikey. At the moment you are generating for each request a new session object which generates a higher load on your script and on the meraki backend
  2. span argument: add the default parameter. That way you won't have to check, if it got provided or not. Just use it 😃
  3. At the moment you are not checking for an invalid input on the parameters, so your code might fail. Try something like this:

     

     

     

 

    try:
        variables = var_parser.parse_args()
    except SystemExit:
        return
    except:
        print("could not parse arguments")
        var_parser.print_help()
        return​

 

 

 

 

  • don't check for the api_key. The DashboardAPI object will do this for you. Just catch the APIKeyError exception.
  • in getnbevents you don't have to count the entries, just do return len(log['events'])

 

return len(log['events'])​

 

gabtoub
Here to help

Thanks @Greenberet , I'll try this today and update the script with your advices 🙂

Get notified when there are additional replies to this discussion.