It is all about networking, technology and Cisco - Learn Something New Everyday

0

Python: Processes and Threads

top – show all processes: Find the proccess: ps aux | head -1; ps aux | grep 1248 How to create a process in Python os.fork() – creates a copy of parent process => we have 2 processes, parent pid = PID, child pid = 0: Fork copies everything – memory, variables, files etc => if you change variable in the...

0

Python Logging

I decided to take a look into Python Logging and start using it instead of print(). Everything is here: Logging HOWTO. Task you want to perform The best tool for the task Display console output for ordinary usage of a command line script or program print() Report events that occur during normal operation of a program (e.g. for status monitoring or...

0

Python: Stealthwatch and Alarms API

It’s been a while since my last post. So many things going on, but I am still here:) Working with ISE Monitoring API I like an option to get errors with code/cause and how/what to check for resolution: I was not able to find any Stealthwatch API for Alarm’s definitions. But there is a cool guide “Security Events and Alarm Categories...

0

Just a little bit about HTML and CSS

HTML <!DOCTYPE html> is placed at the start of an HTML file to indicate to the browser that HTML5 is being used. Tags: <html></html> : contents of website <head></head> : metadata about the page that is useful for the browser when displaying the page <title></title> : title of the page <body></body> : body of the page <a href=“path/to/hello.html”>Click here!</a> : link to hello.html <img src=“path/to/img.jpg” height=”200″ width=”300″> : image...

0

Jinja2 in Python – Render Config

Jinja2 is a full-featured template engine for Python. The first time I used it with Flask, it comes packaged with the powerful Jinja templating language. But it also could be used for rendering configuration. Jinja templates use: {{ … }} – for variable {% … %} – for expressions or logic (like for loops) Jinja2 also allows for conditional statements: Jinja2...

2

Python: Iterators, Generators, and Coroutines

Iterator An iterator is an object that contains a countable number of values and consists of the methods __iter__ and __next__. __iter__: This method is called when an iterator is required for a container. Must always return an iterator __next__: Return the next item from the container. Generator Generator functions allow you to declare a function that behaves like an iterator...

0

Python: Magic Methods, Context Manager

Magic methods __new__: Called to create a new instance of class cls. What is happening at the moment of class creation (like checking if there should be only one instance of such class) __init__: Called after the instance has been created (by __new__())__del__: better not to change:)__str__: Called by str(object) and the built-in functions format() and print() to compute the “informal”...

0

Python: Files, Exceptions, and Errors

Files Opening files using the with statement is recommended because it ensures that the file is automatically closed at the ends of the with the statement. Exceptions Standard exceptions and users exceptions It’s better to catch and work with the specific exception try/except could include: else, that will be executed if no exception occurred finally, will be executed no matter what...

0

Python: Class Inheritance and Compositions

Inheritance  A Derived class inherits from a Base class and is a specialized version of Base. It allows defining a class that inherits all the methods and properties of another class. The syntax for a subclass definition looks like this: Super() function will make the child class inherit all the methods and properties from its parent: Example: Pet is a Base...

0

WebApp: Cisco ISE-Python-Flask

My previous post “Python and ISE Monitor Mode” was about how to collect access-session information from the switch and use it for endpoint verification. Specifically for MAB-only devices – add in the proper Endpoint Group in the Cisco ISE. The result of the script was the file with “failed” devices: With this info, we had to log in to the ISE...