- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 Cacti 上创建了一个关于使用 cacti 和 net-snmp 访问我们基础设施上特定页面的时间的图表。
我通过在文件/etc/snmp/snmpd.conf 中添加两行来扩展功能:
extend stat_page1 /usr/local/bin/cacti/access_page.sh context1
extend stat_page2 /usr/local/bin/cacti/access_page.sh context2
我已重新启动守护程序 snmpd 以加载此配置。
调用的脚本如下所述,具有其他值,因为出于某种原因,我可以显示它。
#!/bin/bash
domain="mydomain"
cookie_name="myCookie"
token="myToken"
if [ $# -eq 1 ]
then
if [ "$1" = "context1" ]
then
target_url="https://${domain}/${1}/page1.html"
TIME=$(curl -s -w "%{time_total}" -o /dev/null --cookie \"${cookie_name}=${token}\" ${target_url})
echo "$TIME"
elif [ "$1" = "context2" ]
then
target_url="https://${domain}/${1}/page2.html"
TIME=$(curl -s -w "%{time_total}" -o /dev/null --cookie \"${cookie_name}=${token}\" ${target_url})
echo "$TIME"
fi
如果我手动启动脚本我有这个
$ /usr/local/bin/cacti/access_page.sh context2
0.061
$ /usr/local/bin/cacti/access_page.sh context1
0.041
当我使用 snmpget 启动脚本时,我得到了这个结果:
snmpwalk -v2c -c myCommunity localhost NET-SNMP-EXTEND-MIB::nsExtendOutput2Table
NET-SNMP-EXTEND-MIB::nsExtendOutLine."stat_page1".1 = STRING: 0.000
NET-SNMP-EXTEND-MIB::nsExtendOutLine."stat_page2".1 = STRING: 0.000
一直以来,我都通过 snmp
命令获得 0.000 值并手动获得真实值。
你能帮我一下吗?,拜托
最佳答案
最近我遇到了 snmp
和调用 curl
命令的执行脚本的问题。
当我搜索一些解决方案时,这篇文章是最接近问题的。
我找到了不禁用 SELinux 的解决方案。
我是 SELinux 的新手,但我通过一些 SELinux 配置解决了这个问题,将来可能会有人感兴趣。
Centos 7
SNMP /etc/snmp/snmpd.conf
配置文件的内容:
# sec.name source community
com2sec myuser default public
# groupName securityModel securityName
group mygroup v2c pad
# name incl/excl subtree mask(optional)
view systemview included .1.3.6.1.4
view systemview included .1.3.6.1.4.1
view systemview included .1.3.6.1.4.1.1234
view systemview included .1.3.6.1.4.1.1234.1
# group context sec.model sec.level prefix read write notif
access mygroup "" any noauth exact systemview none none
perl do "/appli/snmp_scripts/agent.pl"
#!/usr/bin/perl
use NetSNMP::agent (':all');
use NetSNMP::ASN qw(ASN_OCTET_STR ASN_INTEGER);
sub handler {
my ($handler, $registration_info, $request_info, $requests) = @_;
my $request;
for($request = $requests; $request; $request = $request->next()) {
my $oid = $request->getOID();
if ($request_info->getMode() == MODE_GET) {
if ($oid == new NetSNMP::OID(".1.3.6.1.4.1.1581.1.6.2.1.5")) {
$request->setValue(ASN_OCTET_STR,`/path/to/myscript`);
}
}
}
}
my $AGENT_OID = ".1.3.6.1.4.1.1234";
$agent->register("MYAGENT", ".1.3.6.1.4.1.1234",
\&handler);
当我使用 sudo systemctl status snmpd
寻找执行的痕迹时,显示了一些 curl 痕迹:
snmpd: curl: (7) Failed to connect to 127.0.0.1:8081 Permission denied
但是,服务器在此端口运行良好,并且在 SNMP 外部执行的脚本运行良好。
审计日志中生成了 SELinux 错误:
$> sudo grep snmp /var/log/audit/audit.log | audit2allow -w -a
type=AVC msg=audit(1528188940.802:2025): avc: denied { name_connect } for pid=26809 comm="curl" dest=8081 scontext=system_u:system_r:snmpd_t:s0 tcontext=system_u:object_r:transproxy_port_t:s0 tclass=tcp_socket
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.
$> sudo grep snmp /var/log/audit/audit.log | audit2allow -M mysnmpmodule
******************** IMPORTANT ***********************
To make this policy package active, execute:
semodule -i snmpdcanopensocket.pp
按照 audit2allow comm 指示的步骤将新创建的 snmp_t
模块应用于 SELinux。 audit2allow -M
命令在当前目录中生成了两个文件 snmpdcanopensocket.pp snmpdcanopensocket.te。SELinux 需要 .pp 文件来重新映射它的安全规则。
$> semodule -i snmpdcanopensocket.pp
使用 sudo systemctl restart snmp
重启 SNMP 服务
现在,由 SNMP 执行的脚本中的 curl 表现良好,不会以 (7) 错误代码退出。
关于linux - Cacti 通过自定义脚本扩展 snmp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27399918/
我正在尝试通过 SNMP 发送陷阱消息。 网上的例子提到了'sysUpTime'值的设置,但都没有说明。在这种情况下 sysUpTime 的作用是什么? 谢谢! 最佳答案 sysUpTime 是: T
我正在使用一些 SNMP 陷阱来监视应用程序。现在我被告知,如果陷阱中的属性顺序与 MIB 中定义的不同,某些监控系统可能会出现问题。由于 OID 的复杂性可以很容易地用于对属性进行重新排序,我对此感
我想使用 net-snmp 为 PowerPC 板实现 SNMP 代理。 以前它是使用 SMASH 实现的。 SMASH 有一个解析器 它可以读取 MIB 并生成 C 代码(空白函数实现) 我该如何开
在我的网络中,我想扫描启用 snmp 的设备。那么是否有任何单行 snmp 命令,以获取特定 IP 地址范围(如 172.26.1.1 到 172.26.1.255)中启用 snmp 的设备列表。 我
如何使用 C 或 C++ 和 net-snmp 模块接收陷阱。我需要示例代码,但示例位于 http://www.net-snmp.org/使用系统调用但不使用 API 方法。 最佳答案 net-snm
所以我还在学习SNMP,请放轻松。我正在使用 snmp4j,不仅是库,而且我已经加载了源代码,如果它满足我的需要,我不反对修改源代码。我已经编写了一个代理和一个测试客户端。我想要做的是能够检查来自测试
我正在尝试使用 SNMP 从 Brother MCF-9465CDN 获取碳粉量,以便最终使用 Munin 将它们绘制在图表中。我没有得到墨水量。 虽然我对 SNMP 有点陌生,但我认为我正在尝试的应
在我开始之前,我意识到这里已经有一些与 SNMP 相关的问题,但似乎没有多少人得到回答——这可能意味着我问错了地方,但我现在不知道还能去哪里. 这几天我一直在尽我所能阅读有关 SNMP 的内容,但我发
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
在我开始之前,我意识到这里已经有一些与 SNMP 相关的问题,但似乎没有多少人得到回答——这可能意味着我问错了地方,但我现在不知道还能去哪里. 这几天我一直在尽我所能阅读有关 SNMP 的内容,但我发
我可以快速完成 snmp 安装,它工作正常。 在我目前正在研究并尝试修改源的代理模块之一中。我遇到了一个问题,我需要通过代理删除用户。 坚持完成这个: 就像 net-snmp-create-v3-us
去年在我看来,找到一个网页,其中有使用 SNMP 设置工作中心 5755 公共(public)地址簿(姓名、电子邮件)的示例。 现在我的 google-fu 有点生锈了,你能帮帮我吗? 是否有标准化的
如果我试图找到安装了 openWRT 的 Linksys WRT54G 的路由表,我需要哪个 MIB? 最佳答案 那应该是 MIB II。 SNMP 对象 ID (OID) 是 .1.3.6.1.2.
我对 SNMP 有一点了解,但还不够。我需要开发一个可以读取标准 SNMP MIB 并读取/写入各种属性的应用程序。网络端没问题,但实际的 MIB 以及它们可能包含的确切内容对我来说是一种黑色艺术。
我是 SNMP 新手。我必须培养一个经理。我一直在寻找如何为经理编程。我遇到过 WinSNMP、SNMP++ 和 Net-SNMP。 Net-SNMP 的优点是它可以转换来自 MIB 的陷阱内容(它可
在软件定义的网络中,有些东西我仍然没有得到:在传统网络中,我们使用 CLI 或 NETCONF 或者 SNMP 来配置设备,在 SDN 中,我们使用 Openflow 来这样做,但是检索信息呢? 之前
在软件定义的网络中,有些东西我仍然没有得到:在传统网络中,我们使用 CLI 或 NETCONF 或者 SNMP 来配置设备,在 SDN 中,我们使用 Openflow 来这样做,但是检索信息呢? 之前
我正在尝试使用 snmp4j 模拟 SNMP 代理。 我正在尝试向代理注册 MO。 下面是代码片段: static final OID mo1= new OID("1.3.6.1.4.1.1234.1
我希望在 Java 中使用 SNMP 为项目设置监控。我环顾四周,发现了一些软件包:JBossSNMPAdapter和SNMP4J-Agent。我不确定这两者之间有什么区别。 最佳答案 SNMP4j-
我是一名优秀的程序员,十分优秀!