Cloud Native应用交付

  • 首页
  • 关于本站
  • 个人介绍
  • Downloads
  • Repo
    • Github
    • Container
  • F5
    • F5 Python SDK
    • F5-container
    • F5-LBaaS
  • 社交
    • 联系我
    • 微信/微博
    • 公众号
    • 打赏赞助
行至水穷处 坐看云起时
Cloud Native Application Services: cnadn.net
  1. 首页
  2. F5技术
  3. 正文

FW:利用自定义MIB采集标准MIB中不存在的数据

2015年10月9日 9396点热度 0人点赞 0条评论

SNMP (Simple Network Management Protocol) is an internet protocol used to monitor and manage devices including servers, routers, switches and assorted other devices. It allows gathering a glut of data - this can be hardware information (eg. cpu temperature), network information (eg. interface speed) or software information (eg. number of HTTP requests).

However, to get at this information, it first needs to be addressable. SNMP itself does not define which bits of information are available. Instead it uses MIBs, or Management Information Bases which are basically hierarchies or trees of OIDs or object identifiers. SNMP is implemented in numerous devices including the devices we use for load balancing and shaping our traffic.

To load balance our main internet presence we use BIG-IP LTMs from F5. By default, it comes with a rather extensive MIB but sometimes doesn't have exactly what we want. It wasn't until version 11.2.0 that F5 introduced the ability to add custom OIDs to the MIB. Even better is that it lets us run and capture the output of shell commands on the device itself. This functionality gives exactly what is needed to get some data that otherwise wouldn't be automatically available. Without further ado, here is how to use this.

(Fair warning, doing this requires some knowledge of Tcl, but Tcl is a really easy language to pick up.)

First, some information about the OID structure

  • the base OID for F5s BIG-IP devices is .1.3.6.1.4.1.3375.2
  • custom OIDs are added with the .100 suffix (ie. .1.3.6.1.4.1.3375.2.100)

On startup, the SNMP daemon on the BIG-IP checks for a file called /config/snmp/custom_mib.tcl. This file contains the OID definitions and Tcl functions to be called when the OID is requested.

To add a new OID you first have to register it using the register_mib function

1
register_mib ".<oid>" <tcl_function> <type>

where oid is something like ".1", ".2", ".3.1", etc. tcl_function is the name of the function that you want to call. And finally the type of the OID being defined. There are four types supported: int, string, gauge, and counter.

Once we've registered a function, we need to then define that function. So further down in the file, section off a part of it for your custom functions.

For example:

1
2
3
4
5
6
7
proc time {}
{
  set status [catch {exec date +%s} now]
  if {$status != 0} {
    return -1
  } else { return $now }
}

 

It should be noted that the function will receive no arguments, so whatever processing needs to be done needs to be done without context.

It is recommended that any shell commands executed should be wrapped in a catch statement. This way the snmpd is protected slightly. Also, watch out for things like infinite loops or logic errors. Since the Tcl execution happens within the snmpd process, it is possible to do unhealthy things that can have an adverse impact on the daemon.

To pick up the changes to the custom_mib.tcl the SNMP daemon needs to be restarted (bigstart snmpd restart). And of course, the custom OID should be checked to make sure everything is working:

1
snmpwalk -Os -c public -v 2c localhost .1.3.6.1.4.1.3375.2.100.1

Remember to check the log file (/var/log/snmpd.log) for errors.

So while this functionality is interesting, it is much more interesting to see a practical application. The default F5 MIB does not include every bit of detail you might want - sometimes it is only retrievable via the interpreter/shell or even tmsh. So here is an example of harvesting the time in seconds since the last configuration update and making it available:

To get the time in seconds since the last configuration update, BASH can be used to call tmsh:

1
tmsh -c <span class="s2">"list sys db configsync.localconfigtime one-line"</span> | cut -d<span class="se">\"</span> -f2 &gt; /tmp/lastupdate

Unfortunately, this returns a string in which only a single field is needed. With a judicious use of cut the seconds can be extracted and stored. And since this information might be useful outside SNMP, it can be stored on the file system somewhere. To generate this file, putting this into the crontab works.

Now that the data is available in a file, all that is needed now is a simple Tcl function to return the data:

1
2
3
4
5
6
7
8
9
10
11
12
13
register_mib ".1" config_age int
 
proc config_age {}
{
  set now_status [catch {exec date +%s} now]
  set config_status [catch {exec /bin/cat /tmp/lastupdate} config]
  if {$now_status == 0 and $config_status == 0} {
    set result [expr $now - $config]
  } else {
    set result -1
  }
  return $result
}

 

Now this data is available via SNMP. Specifically it is available for Nagios to monitor and large discrepancies between last update time between BIG-IP devices can be alerted. This is just the tip of the iceberg. With some more Tcl knowledge, more complex information can be made available via SNMP. Of course, this was just a quick hack and using cron and temporary files might not be suitable to all use cases, but this does demonstrate the ease and hackability of extending the default MIB of BIG-IP devices.

To read further on customizing MIB entries for BIG-IP devices, take a look at the F5 knowledge base article.

https://support.f5.com/kb/en-us/solutions/public/13000/500/sol13596.html

 

相关文章

  • 项目:k8s Gateway API 的BIG-IP实现
  • CIS增强版在线文档
  • F5-k8s解决方案(2)-基于Calico BGP网络的F5 k8s容器平台方案实践
  • openstack heat模板之配置基本LB到F5 BIGIP
  • F5常见log日志解释
本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: F5 MIB SNMP
最后更新:2015年10月9日

纳米

linjing.io

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

页面AI聊天助手

纳米

linjing.io

☁️迈向Cloud Native ADC ☁️

认证获得:
TOGAF: ID 152743
Kubernetes: CKA #664
Microsoft: MCSE MCDBA
Cisco: CCNP
Juniper: JNCIS
F5:
F5 Certified Solution Expert, Security
F5 Certified Technology Specialist, LTM/GTM/APM/ASM
F5 Certified BIG-IP Administrator
  • 点击查看本博技术要素列表
  • 归档
    分类
    • AI
    • Automation
    • Avi Networks
    • Cisco ACI
    • CISCO资源
    • F5 with ELK
    • F5-Tech tips
    • F5技术
    • Juniper
    • Linux
    • NGINX
    • SDN
    • ServiceMesh
    • WEB编程
    • WINDOWS相关
    • 业界文章
    • 交换机技术
    • 化云为雨/Openstack
    • 协议原理
    • 容器/k8s
    • 我的工作
    • 我的生活
    • 网站技术
    • 路由器技术
    • 项目案例
    标签聚合
    neutron istio network flannel api F5 nginx k8s openstack envoy gtm irule docker bigip DNS
    最近评论
    汤姆 发布于 8 个月前(09月10日) 嗨,楼主,里面的json怎么下载啊,怎么收费啊?
    汤姆 发布于 8 个月前(09月09日) 大佬,kib的页面可以分享下吗?谢谢
    zhangsha 发布于 1 年前(05月12日) 资料发给我下,谢谢纳米同志!!!!lyx895@qq.com
    李成才 发布于 1 年前(01月02日) 麻烦了,谢谢大佬
    纳米 发布于 1 年前(01月02日) 你好。是的,因为以前下载系统插件在一次升级后将所有的下载生成信息全弄丢了。所以不少文件无法下载。DN...
    浏览次数
    • Downloads - 183,772 views
    • 联系我 - 118,966 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 116,509 views
    • Github - 103,659 views
    • F5常见log日志解释 - 79,774 views
    • 从传统ADC迈向CLOUD NATIVE ADC - 下载 - 74,623 views
    • Sniffer Pro 4 70 530抓包软件 中文版+视频教程 - 74,320 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 67,770 views
    • 关于本站 - 60,909 views
    • 这篇文档您是否感兴趣 - 55,495 views
    链接表
    • F5SE创新
    • Jimmy Song‘s Blog
    • SDNlab
    • Service Mesh社区
    • 三斗室
    • 个人profile
    • 云原生社区

    COPYRIGHT © 2023 Cloud Native 应用交付. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    京ICP备14048088号-1

    京公网安备 11010502041506号