SlideShare a Scribd company logo
1 of 39
Download to read offline
Tailored SNMP
monitoring
Your own SNMP MIB and
sub-agent with Python and
python-netsnmpagent
OSMC 2018
November 6th, 2018
Pieter Hollants
Pieter who?
Frankfurt, Germany-based developer
(mostly Python) but also...
➔
3y IT support in Netware/Win 95 times
➔
9y (Senior) Intern at SUSE Consulting
➔
4y Linux Systems Engineer at German Air Traffic
Control (e.g. automated installations of high
availability-systems, hardware standardization)
...and freelancing since over 15y (dev & admin)
MIB?
You’re down with…?
MIB
➔
Management Information Base
➔
Used to monitor and configure devices remotely
➔
Structured as tree with nameless root
➔
Defines entities called Managed Objects
➔
Access protocol “on the wire”: SNMP (Simple Network
Management Protocol)
MIB modules
➔
MIB modules (“MIBs”) define
branches of the tree, can be
enterprise-specific or generic,
e.g.:
➔
RFC 2863: IF-MIB (network
interfaces)
➔
RFC 4022: TCP/IP MIB
➔
CISCOSB-MIB
➔
Defined in text files using
ASN.1 subset called SMI
(Structure of Management
Information), v2: RFC2578
➔
Definition != Implementation
Wikipedia / CC-BY-SA
Managed Objects
➔
Uniquely identified by OID (Object Identifier)
➔
OIDs represented as ordered series of numbers (e.g. “.1.3.6.1.4.1”)
or ASCII text labels (e.g. “.iso.org.dod. internet.private.enterprise”)
➔
Enterprise-specific OIDs with IANA assigned Enterprise Number
➔
https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers
➔
Two categories of data types:
➔
Scalar objects:
➔
(Un)Signed Integers
➔
Counters, Gauges, Time ticks
➔
Octet Strings/Display Strings, Bit Strings
➔
Network addresses
➔
Object identifiers
➔
Tabular objects (scalar objects grouped in tables)
Who’d write their own MIB?
➔
Application programmers wanting to expose internal
metrics (e.g. transactions per second)
➔
OEMs (e.g. Nasuni Edge Appliance: https://cdn2.hubspot.net/
hubfs/3316942/Nasuni.com-assets/Support-Docs/Nasuni_Filer_Third-
Party_Licensing_Guide.pdf)
➔
End users wishing to unify otherwise spread-out
information under a common tree (e.g. vendor-neutral
hardware agent used by German Air Traffic Control)
➔
InfraOps (e.g. DNSSEC monitoring:
http://www.delaat.net/rp/2014-2015/p38/presentation.pdf)
➔
You? ;)
MIB deep dive
Not Bernd Erk
(Disclaimer: I know nothing about diving.)
MIB deep dive (5m)
➔
Formally defines “<MIBNAME>“ as everything between
“BEGIN” and “END”
➔
Multiple MIB modules in a text file possible but uncommon
➔
Two dashes (“--”): comment lines
MIB deep dive (10m)
➔
Imports definitions (”features”) from existing MIBs,
similar to “from … import …” in Python
➔
RFC 2579: SNMPv2-TC, RFC 2580: SNMPv2-CONF
➔
AgentX? We’ll see later...
MIB deep dive (15m)
➔
Collects module purpose, contact information,
description, revision information
➔
Defined as OID of subtree this MIB handles (“plugs in”)
➔
Must be first item after module header and imports
Wrong OID! Why?
MIB deep dive (20m)
➔
Associates a name with subtrees in a particular part of the
MIB module’s OID tree, similar to naming subdirs
➔
For human convenience, technically not really required
➔
len(OID subtree def) == 2
➔
“[..] must not be included in an IMPORTS statement”
MIB deep dive (25m)
➔
Defines scalar variables in a particular part of the MIB
module’s OID tree, similar to naming files
➔
SYNTAX: type of the variable
➔
MAX-ACCESS: read-only/read-write/not-accessible/...
➔
STATUS: current/deprecated/obsolete
➔
DESCRIPTION: for humans and humanoids
MIB deep dive (30m)
➔
Defines a “row” as a SEQUENCE of scalar MOs
➔
Simulation of table through N subtrees ~= columns as
defined here (holes possible!)
➔
MOs referenced with name and type only
➔
Still need explicit definition...
MIB deep dive (32m)
➔
Definitions of columns in a row
➔
MAX-ACCESS not-accessible in practical use for row that
will be used as index row (here the only one)
➔
In this example other rows will be read-only
MIB deep dive (34m)
➔
Table ~= SEQUENCE OF (SEQUENCE ...)
➔
Both table and row themselves not-accessible
➔
INDEX magically overwrites 1 with values in referenced index
column (values = indexes)
MIB deep dive (36m)
➔
Table object not-accessible → snmpget = no such object
➔
Same for defined row, e.g. firstTable.1 = no such object
➔
snmpwalk reveals low-level .<table>.<column>.<row> construct
➔
snmptable knows how to interpret tables semantics
➔
firstTableRowIndex values = indexes
MIB deep dive (40m)
➔
Always check your MIBs with “smilint”
➔
Part of libsmi, other nice tools such as “smidiff”, “smidump”…
➔
http://www.ibr.cs.tu-bs.de/projects/libsmi/
➔
Also validate with increased “-lX” severity levels, then learn
about MIB concepts you haven’t heard about yet (e.g.
conformance groups)
Out of breath?
Let’s
define
our
own
MIB!
Let’s
define
our
own
MIB!
We need something
to monitor...
Our GT-MIB (1/2)
...we should actually register our
own Enterprise Number with IANA!
http://pen.iana.org/pen/PenApplication.page
Our GT-MIB (2/2)
Index column doesn’t necessarily
have to be named “...Index”
Implementing SNMP
➔
De-facto standard: Net-SNMP suite (formerly called
UCD-SNMP), found in all major distros
➔
Current release: 5.8 (July 16th, 2018)
➔
Consists of
➔
Command-line applications such as snmpget,
snmpset, snmpwalk, snmptable, snmptranslate...
➔
Extensible agent (software that handles SNMP
requests) with built-in support for wide range of
MIB modules: snmpd
➔
Daemon for receiving SNMP traps: snmptrapd
➔
Libraries for developing SNMP apps, C/Perl APIs
➔
Tools such as mib2c
Implementing MIBs
➔
snmpd: built-in support for number of MIBs, e.g. IF-MIB
➔
Extensible: snmpd as master agent allows for subagents
implementing parts of the MIB (MIB modules)
➔
Three alternatives differing in data representation and
communication mechanisms:
➔
Proxied SNMP: standard SNMP packet format, full fledged
agent unaware of subagent role on non-standard port
➔
SMUX (RFC 1227): standard SNMP packet format,
subagent registers with master agent, issues, historical
➔
AgentX (RFC 2741): more compact packet format,
advanced functionality, state of the art, enabled with
“master agentx” line in snmpd.conf
Net-SNMP mib2c (1/2)
mib2c currently can’t handle
MIBs with both tables and scalars
Different approaches to
implement tables possible
Input: MIB
Output: Skeleton C code
Net-SNMP mib2c (2/2)
Only init callback
shown here
Net-SNMP mib2c (2/2)
Yeah, okay, C code but…
isn’t there something easier?
Net-SNMP mib2c (2/2)
Yeah, okay, C code but…
isn’t there something easier?
Python & SNMP support
➔
Net-SNMP ships with Python “netsnmp” module
➔
2500 lines C code that abstract Net-SNMP C API
➔
SNMP client only: get, walk… operations
➔
C API has support for writing agents as well (as seen
with mib2c)
➔
Idea: access C API directly from Python using ctypes,
imitating agents written in C
➔
Existing python-agentx module on Sourceforge
➔
Design issues (= I didn’t grok it ;)
➔
Orphaned
➔
2015: pyagentx module on Github, actually implements
AgentX network protocol, meanwhile orphaned as well
Hello python-netsnmpagent!
➔
Python module I wrote back in 2013 driven by
requirements at German Air Traffic Control
➔
LGPLv3 licensed
➔
Source at https://github.com/pief/python-netsnmpagent
➔
Distributable archives on PyPI
➔
RPMs available on Open Build Service
➔
Compatible with Python 2.6, 2.7 and >=3.5
➔
Tested with net-snmp 5.4.x (SLES11…), 5.7.x, 5.8
➔
Two extensively commented files
➔
netsnmpapi.py (ctypes stuff for internal use), 317 LOC
➔
netsnmpagent.py (abstraction classes), 839 LOC
➔
No docs but example MIBs/agents included
Our gtmib_agent.py (1/3)
Used by Net-SNMP e.g.
to translate OIDs
Default value for column
Classes representing
data types
Only import required
Column number
Class factory
OID this SNMP object handles
Our gtmib_agent.py (2/3)
Values for index and
data columns
Connects to master agent –
no more object registrations!
Our gtmib_agent.py (3/3)
Signal handler
triggered eg. by ^C
Net-SNMP internal
packet processing
Example in this form not
well-suited for real agents. Why?
Et voila!
Live demo anyone?
The fineprint
➔
Currently no support for callback pattern, i.e.
data structures must be periodically refreshed
➔
check_and_process() blocks, threading required
to do processing and data updating in parallel
➔
Development has slowed somewhat because no
active sponsor anymore → your chance?
➔
Some open issues
➔
No support for SNMP traps yet (but MR exists)
➔
Only rudimentary unit tests
➔
It’s Open Source, take your chance!
EOT
Pieter Hollants
pieter@hollants.com
pfhllnts
pfhllnts@mstdn.io

More Related Content

What's hot

NATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATSNATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATS
Raül Pérez
 
Decentralized possibilities with filecoin &amp; ipfs_encode filecoin club
Decentralized possibilities with filecoin &amp; ipfs_encode filecoin clubDecentralized possibilities with filecoin &amp; ipfs_encode filecoin club
Decentralized possibilities with filecoin &amp; ipfs_encode filecoin club
KlaraOrban
 

What's hot (20)

A Cassandra driver from and for the Lua community
A Cassandra driver from and for the Lua communityA Cassandra driver from and for the Lua community
A Cassandra driver from and for the Lua community
 
Encode
EncodeEncode
Encode
 
NATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATSNATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATS
 
stackconf 2021 | Continuous Security – integrating security into your pipelines
stackconf 2021 | Continuous Security – integrating security into your pipelinesstackconf 2021 | Continuous Security – integrating security into your pipelines
stackconf 2021 | Continuous Security – integrating security into your pipelines
 
Decentralized possibilities with filecoin &amp; ipfs_encode filecoin club
Decentralized possibilities with filecoin &amp; ipfs_encode filecoin clubDecentralized possibilities with filecoin &amp; ipfs_encode filecoin club
Decentralized possibilities with filecoin &amp; ipfs_encode filecoin club
 
A Kong retrospective: from 0.10 to 0.13
A Kong retrospective: from 0.10 to 0.13A Kong retrospective: from 0.10 to 0.13
A Kong retrospective: from 0.10 to 0.13
 
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
stackconf 2021 | Embracing change: Policy-as-code for Kubernetes with OPA and...
 
Nzitf Velociraptor Workshop
Nzitf Velociraptor WorkshopNzitf Velociraptor Workshop
Nzitf Velociraptor Workshop
 
FIWARE Wednesday Webinars - Core Context Management
FIWARE Wednesday Webinars - Core Context ManagementFIWARE Wednesday Webinars - Core Context Management
FIWARE Wednesday Webinars - Core Context Management
 
Secrets management vault cncf meetup
Secrets management vault cncf meetupSecrets management vault cncf meetup
Secrets management vault cncf meetup
 
Redecentralizing the Web: IPFS and Filecoin
Redecentralizing the Web: IPFS and FilecoinRedecentralizing the Web: IPFS and Filecoin
Redecentralizing the Web: IPFS and Filecoin
 
Netflow Analysis using Elastic Stack - 조인중
Netflow Analysis using Elastic Stack - 조인중Netflow Analysis using Elastic Stack - 조인중
Netflow Analysis using Elastic Stack - 조인중
 
stackconf 2021 | GitOps: yea or nay?
stackconf 2021 | GitOps: yea or nay?stackconf 2021 | GitOps: yea or nay?
stackconf 2021 | GitOps: yea or nay?
 
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
Control Plane: Security Rationale for Istio (DevSecOps - London Gathering, Ja...
 
stackconf 2021 | First hand experience: How Nextcloud stayed productive durin...
stackconf 2021 | First hand experience: How Nextcloud stayed productive durin...stackconf 2021 | First hand experience: How Nextcloud stayed productive durin...
stackconf 2021 | First hand experience: How Nextcloud stayed productive durin...
 
OSMC 2018 | Integrating Check_MK agent into Thruk – Windows monitoring made e...
OSMC 2018 | Integrating Check_MK agent into Thruk – Windows monitoring made e...OSMC 2018 | Integrating Check_MK agent into Thruk – Windows monitoring made e...
OSMC 2018 | Integrating Check_MK agent into Thruk – Windows monitoring made e...
 
Cloud Native User Group: Shift-Left Testing IaC With PaC
Cloud Native User Group: Shift-Left Testing IaC With PaCCloud Native User Group: Shift-Left Testing IaC With PaC
Cloud Native User Group: Shift-Left Testing IaC With PaC
 
MRA AMA Part 8: Secure Inter-Service Communication
MRA AMA Part 8: Secure Inter-Service CommunicationMRA AMA Part 8: Secure Inter-Service Communication
MRA AMA Part 8: Secure Inter-Service Communication
 
MRA AMA Part 7: The Circuit Breaker Pattern
MRA AMA Part 7: The Circuit Breaker PatternMRA AMA Part 7: The Circuit Breaker Pattern
MRA AMA Part 7: The Circuit Breaker Pattern
 
Neutron high availability open stack architecture openstack israel event 2015
Neutron high availability  open stack architecture   openstack israel event 2015Neutron high availability  open stack architecture   openstack israel event 2015
Neutron high availability open stack architecture openstack israel event 2015
 

Similar to OSMC 2018 | Tailored SNMP monitoring – Your own SNMP MIB and sub-agent with Python and python-netsnmpagent by Pieter Hollants

Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8
guest441c58b71
 
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep diveITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp
 
Open Source Virtualization Hacks
Open Source Virtualization HacksOpen Source Virtualization Hacks
Open Source Virtualization Hacks
Niel Bornstein
 

Similar to OSMC 2018 | Tailored SNMP monitoring – Your own SNMP MIB and sub-agent with Python and python-netsnmpagent by Pieter Hollants (20)

Node-RED and Minecraft - CamJam September 2015
Node-RED and Minecraft - CamJam September 2015Node-RED and Minecraft - CamJam September 2015
Node-RED and Minecraft - CamJam September 2015
 
Dmitriy D1g1 Evdokimov - DBI Intro
Dmitriy D1g1 Evdokimov - DBI IntroDmitriy D1g1 Evdokimov - DBI Intro
Dmitriy D1g1 Evdokimov - DBI Intro
 
Userland Hooking in Windows
Userland Hooking in WindowsUserland Hooking in Windows
Userland Hooking in Windows
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8Cracking Into Embedded Devices - HACK.LU 2K8
Cracking Into Embedded Devices - HACK.LU 2K8
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
Inria Tech Talk : RIOT, l'OS libre pour vos objets connectés #IoT
Inria Tech Talk : RIOT, l'OS libre pour vos objets connectés #IoTInria Tech Talk : RIOT, l'OS libre pour vos objets connectés #IoT
Inria Tech Talk : RIOT, l'OS libre pour vos objets connectés #IoT
 
Snmp
SnmpSnmp
Snmp
 
Command line for the beginner - Using the command line in developing for the...
Command line for the beginner -  Using the command line in developing for the...Command line for the beginner -  Using the command line in developing for the...
Command line for the beginner - Using the command line in developing for the...
 
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep diveITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
 
Build your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resourcesBuild your own discovery index of scholary e-resources
Build your own discovery index of scholary e-resources
 
Ansible Hands On
Ansible Hands OnAnsible Hands On
Ansible Hands On
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fast
 
Homebrew Your Own Metrics - An IBM Domino Administrator's Guide to SNMP (MWLU...
Homebrew Your Own Metrics - An IBM Domino Administrator's Guide to SNMP (MWLU...Homebrew Your Own Metrics - An IBM Domino Administrator's Guide to SNMP (MWLU...
Homebrew Your Own Metrics - An IBM Domino Administrator's Guide to SNMP (MWLU...
 
Open Source Virtualization Hacks
Open Source Virtualization HacksOpen Source Virtualization Hacks
Open Source Virtualization Hacks
 
RAT - Repurposing Adversarial Tradecraft
RAT - Repurposing Adversarial TradecraftRAT - Repurposing Adversarial Tradecraft
RAT - Repurposing Adversarial Tradecraft
 
Python3 (boto3) for aws
Python3 (boto3) for awsPython3 (boto3) for aws
Python3 (boto3) for aws
 
Building A Sensor Network Controller
Building A Sensor Network ControllerBuilding A Sensor Network Controller
Building A Sensor Network Controller
 
TIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by stepTIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by step
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 

OSMC 2018 | Tailored SNMP monitoring – Your own SNMP MIB and sub-agent with Python and python-netsnmpagent by Pieter Hollants

  • 1. Tailored SNMP monitoring Your own SNMP MIB and sub-agent with Python and python-netsnmpagent OSMC 2018 November 6th, 2018 Pieter Hollants
  • 2. Pieter who? Frankfurt, Germany-based developer (mostly Python) but also... ➔ 3y IT support in Netware/Win 95 times ➔ 9y (Senior) Intern at SUSE Consulting ➔ 4y Linux Systems Engineer at German Air Traffic Control (e.g. automated installations of high availability-systems, hardware standardization) ...and freelancing since over 15y (dev & admin)
  • 5. MIB ➔ Management Information Base ➔ Used to monitor and configure devices remotely ➔ Structured as tree with nameless root ➔ Defines entities called Managed Objects ➔ Access protocol “on the wire”: SNMP (Simple Network Management Protocol)
  • 6. MIB modules ➔ MIB modules (“MIBs”) define branches of the tree, can be enterprise-specific or generic, e.g.: ➔ RFC 2863: IF-MIB (network interfaces) ➔ RFC 4022: TCP/IP MIB ➔ CISCOSB-MIB ➔ Defined in text files using ASN.1 subset called SMI (Structure of Management Information), v2: RFC2578 ➔ Definition != Implementation Wikipedia / CC-BY-SA
  • 7. Managed Objects ➔ Uniquely identified by OID (Object Identifier) ➔ OIDs represented as ordered series of numbers (e.g. “.1.3.6.1.4.1”) or ASCII text labels (e.g. “.iso.org.dod. internet.private.enterprise”) ➔ Enterprise-specific OIDs with IANA assigned Enterprise Number ➔ https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers ➔ Two categories of data types: ➔ Scalar objects: ➔ (Un)Signed Integers ➔ Counters, Gauges, Time ticks ➔ Octet Strings/Display Strings, Bit Strings ➔ Network addresses ➔ Object identifiers ➔ Tabular objects (scalar objects grouped in tables)
  • 8. Who’d write their own MIB? ➔ Application programmers wanting to expose internal metrics (e.g. transactions per second) ➔ OEMs (e.g. Nasuni Edge Appliance: https://cdn2.hubspot.net/ hubfs/3316942/Nasuni.com-assets/Support-Docs/Nasuni_Filer_Third- Party_Licensing_Guide.pdf) ➔ End users wishing to unify otherwise spread-out information under a common tree (e.g. vendor-neutral hardware agent used by German Air Traffic Control) ➔ InfraOps (e.g. DNSSEC monitoring: http://www.delaat.net/rp/2014-2015/p38/presentation.pdf) ➔ You? ;)
  • 9. MIB deep dive Not Bernd Erk (Disclaimer: I know nothing about diving.)
  • 10. MIB deep dive (5m) ➔ Formally defines “<MIBNAME>“ as everything between “BEGIN” and “END” ➔ Multiple MIB modules in a text file possible but uncommon ➔ Two dashes (“--”): comment lines
  • 11. MIB deep dive (10m) ➔ Imports definitions (”features”) from existing MIBs, similar to “from … import …” in Python ➔ RFC 2579: SNMPv2-TC, RFC 2580: SNMPv2-CONF ➔ AgentX? We’ll see later...
  • 12. MIB deep dive (15m) ➔ Collects module purpose, contact information, description, revision information ➔ Defined as OID of subtree this MIB handles (“plugs in”) ➔ Must be first item after module header and imports Wrong OID! Why?
  • 13. MIB deep dive (20m) ➔ Associates a name with subtrees in a particular part of the MIB module’s OID tree, similar to naming subdirs ➔ For human convenience, technically not really required ➔ len(OID subtree def) == 2 ➔ “[..] must not be included in an IMPORTS statement”
  • 14. MIB deep dive (25m) ➔ Defines scalar variables in a particular part of the MIB module’s OID tree, similar to naming files ➔ SYNTAX: type of the variable ➔ MAX-ACCESS: read-only/read-write/not-accessible/... ➔ STATUS: current/deprecated/obsolete ➔ DESCRIPTION: for humans and humanoids
  • 15. MIB deep dive (30m) ➔ Defines a “row” as a SEQUENCE of scalar MOs ➔ Simulation of table through N subtrees ~= columns as defined here (holes possible!) ➔ MOs referenced with name and type only ➔ Still need explicit definition...
  • 16. MIB deep dive (32m) ➔ Definitions of columns in a row ➔ MAX-ACCESS not-accessible in practical use for row that will be used as index row (here the only one) ➔ In this example other rows will be read-only
  • 17. MIB deep dive (34m) ➔ Table ~= SEQUENCE OF (SEQUENCE ...) ➔ Both table and row themselves not-accessible ➔ INDEX magically overwrites 1 with values in referenced index column (values = indexes)
  • 18. MIB deep dive (36m) ➔ Table object not-accessible → snmpget = no such object ➔ Same for defined row, e.g. firstTable.1 = no such object ➔ snmpwalk reveals low-level .<table>.<column>.<row> construct ➔ snmptable knows how to interpret tables semantics ➔ firstTableRowIndex values = indexes
  • 19. MIB deep dive (40m) ➔ Always check your MIBs with “smilint” ➔ Part of libsmi, other nice tools such as “smidiff”, “smidump”… ➔ http://www.ibr.cs.tu-bs.de/projects/libsmi/ ➔ Also validate with increased “-lX” severity levels, then learn about MIB concepts you haven’t heard about yet (e.g. conformance groups)
  • 23.
  • 24. Our GT-MIB (1/2) ...we should actually register our own Enterprise Number with IANA! http://pen.iana.org/pen/PenApplication.page
  • 25. Our GT-MIB (2/2) Index column doesn’t necessarily have to be named “...Index”
  • 26. Implementing SNMP ➔ De-facto standard: Net-SNMP suite (formerly called UCD-SNMP), found in all major distros ➔ Current release: 5.8 (July 16th, 2018) ➔ Consists of ➔ Command-line applications such as snmpget, snmpset, snmpwalk, snmptable, snmptranslate... ➔ Extensible agent (software that handles SNMP requests) with built-in support for wide range of MIB modules: snmpd ➔ Daemon for receiving SNMP traps: snmptrapd ➔ Libraries for developing SNMP apps, C/Perl APIs ➔ Tools such as mib2c
  • 27. Implementing MIBs ➔ snmpd: built-in support for number of MIBs, e.g. IF-MIB ➔ Extensible: snmpd as master agent allows for subagents implementing parts of the MIB (MIB modules) ➔ Three alternatives differing in data representation and communication mechanisms: ➔ Proxied SNMP: standard SNMP packet format, full fledged agent unaware of subagent role on non-standard port ➔ SMUX (RFC 1227): standard SNMP packet format, subagent registers with master agent, issues, historical ➔ AgentX (RFC 2741): more compact packet format, advanced functionality, state of the art, enabled with “master agentx” line in snmpd.conf
  • 28. Net-SNMP mib2c (1/2) mib2c currently can’t handle MIBs with both tables and scalars Different approaches to implement tables possible Input: MIB Output: Skeleton C code
  • 29. Net-SNMP mib2c (2/2) Only init callback shown here
  • 30. Net-SNMP mib2c (2/2) Yeah, okay, C code but… isn’t there something easier?
  • 31. Net-SNMP mib2c (2/2) Yeah, okay, C code but… isn’t there something easier?
  • 32. Python & SNMP support ➔ Net-SNMP ships with Python “netsnmp” module ➔ 2500 lines C code that abstract Net-SNMP C API ➔ SNMP client only: get, walk… operations ➔ C API has support for writing agents as well (as seen with mib2c) ➔ Idea: access C API directly from Python using ctypes, imitating agents written in C ➔ Existing python-agentx module on Sourceforge ➔ Design issues (= I didn’t grok it ;) ➔ Orphaned ➔ 2015: pyagentx module on Github, actually implements AgentX network protocol, meanwhile orphaned as well
  • 33. Hello python-netsnmpagent! ➔ Python module I wrote back in 2013 driven by requirements at German Air Traffic Control ➔ LGPLv3 licensed ➔ Source at https://github.com/pief/python-netsnmpagent ➔ Distributable archives on PyPI ➔ RPMs available on Open Build Service ➔ Compatible with Python 2.6, 2.7 and >=3.5 ➔ Tested with net-snmp 5.4.x (SLES11…), 5.7.x, 5.8 ➔ Two extensively commented files ➔ netsnmpapi.py (ctypes stuff for internal use), 317 LOC ➔ netsnmpagent.py (abstraction classes), 839 LOC ➔ No docs but example MIBs/agents included
  • 34. Our gtmib_agent.py (1/3) Used by Net-SNMP e.g. to translate OIDs Default value for column Classes representing data types Only import required Column number Class factory OID this SNMP object handles
  • 35. Our gtmib_agent.py (2/3) Values for index and data columns Connects to master agent – no more object registrations!
  • 36. Our gtmib_agent.py (3/3) Signal handler triggered eg. by ^C Net-SNMP internal packet processing Example in this form not well-suited for real agents. Why?
  • 38. The fineprint ➔ Currently no support for callback pattern, i.e. data structures must be periodically refreshed ➔ check_and_process() blocks, threading required to do processing and data updating in parallel ➔ Development has slowed somewhat because no active sponsor anymore → your chance? ➔ Some open issues ➔ No support for SNMP traps yet (but MR exists) ➔ Only rudimentary unit tests ➔ It’s Open Source, take your chance!