设置网络监控和资产管理系统
![]() 此页面最初是一个有趣的项目,但由于时间限制,未能完全完成。按照此指南操作将获得一台服务器,该服务器可以对给定的子网执行 ping 扫描,将扫描结果提交给 OpenAudit,以便 Windows 机器能够被自动审计,然后解析结果,并根据已安装的某些软件(例如 Microsoft Exchange 或 Lotus Domino)将找到的计算机添加到 NagioSQL 中的不同 Nagios 主机组。遗憾的是,OpenAudit + Nagios 集成的最终代码,即从 NagioSQL 数据库导出数据到 nagios 配置文件,然后向 Nagios 发出 SIGHUP 以使更改生效的部分,尚未实现。一旦实现,此页面将会更新。 |
目标
基本概念是将上述应用/实用程序组合起来,创建一个易于设置且维护成本低的网络监控系统,该系统还可以借助 OpenAudit 跟踪资产清单。配置中的冗余条目将被保持在最低限度(希望如此)。新设备应自动添加到监控系统中,并附带相关服务(例如,运行 MS Exchange 的 Windows 服务器可能需要监控 CPU 负载、硬盘可用空间、正在运行的服务和 Exchange 队列等基本服务,而运行在 Alpine Linux 上的路由器可能需要监控路由表、吞吐量和 opennhrp)。此外,还应监控软件许可,以确保 Windows 计算机不会超出购买的许可证数量。
完成后,用于连接 OpenAudit 和监控组件的脚本将被称为 AMAAPS(自动监控和审计填充系统)(WIP 可在 https://github.com/jbilyk/AMAAPS 获取)
为了完成上述目标,本指南将设置(列表可能会更改):
本指南将假定:
- 您了解您的网络设置(至少知道存在的子网)
- 您的网络允许 ICMP ping 数据包到达您希望发现并自动添加到系统中的每个设备
- 您的防火墙(无论是在您的网络设备还是最终用户设备上)允许流量返回到正在设置的服务器,如果是 Windows 主机,则允许 RPC 调用,尤其是在 Win7 Pro 机器上运行审计时,请仔细检查本地防火墙设置,以允许与 OpenAudit 计算机之间的流量(这将允许在通过 OpenAudit 计算机触发时正确进行审计)。
- 如果您正在审计 Windows 域,则您有权访问一个在每台计算机上都具有本地管理员权限的帐户(在 Win XP 上,具有 Power User 权限的用户可能就足够了)。
步骤
安装 lighttpd
基本安装
为了首先安装额外的软件包,请激活社区软件包并更新软件包索引
安装所需的软件包
# apk add lighttpd php82 fcgi php82-cgi
配置 Lighttpd
编辑 lighttpd.conf (/etc/lighttpd/lighttpd.conf) 并取消注释以下行
/etc/lighttpd/lighttpd.conf 的内容
编辑 mod_fastcgi.conf (/etc/lighttpd/mod_fastcgi.conf),找到并将 /usr/bin/php-cgi 更改为 /usr/bin/php-cgi82。
/etc/lighttpd/mod_fastcgi.conf 的内容
启动 lighttpd
服务并将其添加到默认运行级别
# rc-service lighttpd start # rc-update add lighttpd default
配置 MySQL
/usr/bin/mysql_install_db --user=mysql rc-service mysql start && rc-update add mysql default /usr/bin/mysqladmin -u root password 'password'
安装 Nagios、nagios-plugins 和 Nagiosql 以及其他需要的软件包
apk add nagios nagios-web nagios-plugins nagiosql php-mysqli php-mysql
为 nagiosql 虚拟主机创建软链接'
ln -s /usr/share/webapps/nagiosql /var/www/localhost/htdocs/nagiosql
更改 nagiosql 的权限
chown lighttpd:lighttpd /usr/share/webapps/nagiosql/config
浏览到 http://localhost/nagiosql 并按照设置说明进行操作。创建文件夹 /usr/share/webapps/openaudit 并链接到虚拟主机文件夹
mkdir /usr/share/webapps/openaudit chown lighttpd:lighttpd /usr/share/webapps/openaudit ln -s /usr/share/webapps/openaudit /var/www/localhost/htdocs/openaudit</nowiki>
从 https://downloads.sourceforge.net/open-audit/openauditrelease-09.12.23-SVN1233.zip 下载 openaudit 并解压到 /usr/share/webapps/openaudit。
在 Windows 服务器上,创建计划任务以定期运行 ping-sweep-main.bat、lookup-main.bat 和 insert-hosts-main.bat。由于 insert-hosts-main.bat 文件对其他 Windows 服务器运行 RPC 调用,因此目前此部分需要在 Windows 服务器上运行...
未完待续...
AMAAPS 现在有了代码,可以将使用 OpenAudit 找到的 Windows 主机添加到 NagioSQL 主机表中。现在还将 Exchange 服务器、SQL 服务器和 Lotus Domino 服务器添加到相应的主机组。
现在:完成 NagioSQL 配置,使其具有
- 半合理的默认设置(主机组设置、检查命令等)和
- 在 Nagios 配置更改时触发重新加载
注释
SNMPTT 正确接收 snmp traps 并将它们发送到 Nagios,但它们尚未以任何方式解析。
已将 nmap 结果导入 OpenAudit。需要在 admin_nmap_input.php 第 48 行进行更改(“Interesting ports on” -> “Nmap scan report for”),为此已向上游提交了错误报告。
已将可 ping 通/可解析的主机自动添加到 OpenAudit
- 当使用以下脚本自动添加时,检测到了 Windows 版本 2000(Pro 和 Server)、XP Pro、2003(包括 R2)(Std/Ent)(x86/x64)。仅当本地防火墙设置为允许 RPC 流量通过时,才检测到 Windows 7 Pro
- 检测到某些打印机(HP LJ3300、LJ8100),而其他型号则未检测到
- 未添加任何网络设备(交换机/路由器)
- 计划从 OpenAudit + 已安装软件查询 Windows 服务器
- 检查 nagiosql 中是否包含每个服务器
- 如果它没有,则添加主机监控 + 基本服务
- 对于每个 MS 软件(例如 Exchange、SQL、DPM),添加服务
- 通过 LLDP 查询核心交换机以找出设备位置并自动设置依赖关系
- SNMPTT 集成到 Nagios(基于 OpenAudit 中的设备信息设置)- 请参考 http://xavier.dusart.free.fr/joomla/index.php/en/nagios/47-traps-snmp-dans-nagios[Dead Link]
随机脚本
由于部分实现运行在 Windows 上(由于从 OpenAudit 运行 VBScript 以通过 RPC 收集 Windows 服务器/工作站信息),因此下面列出了一组在 Windows 上运行的脚本。
Ping-sweep*.bat:对 subnet.txt 中每个子网执行 nmap ping 扫描,并将所有启动的主机写入文件 lookup*.bat:对每个可 ping 通的主机执行 A 记录 DNS 查询,并将结果写入文件 insert-hosts*:对于每个可解析的主机,下载 vbscript 以将主机信息插入到 openaudit 中(使用 WMI 获取硬件、操作系统和软件信息)
ping-sweep-main.bat
cd C:\Program Files\WAMP\www\openaudit\scripts\scans for /F %%i in (subnets.txt) do ping-sweep-backend.bat %%i
ping-sweep-backend.bat
@echo off cd C:\Program Files\WAMP\www\openaudit\scripts\scans del %1.ip.txt nmap -sP %1 | "C:\program files\utilities\bin\grep" "Nmap scan report for" | "C:\Program Files\Utilities\bin\awk" -F " " "{print $NF}" | "C:\Program Files\Utilities\bin\awk" -F "(" "{print $NF}" | "C:\Program Files\Utilities\bin\awk" -F ")" "{print $1}" >> %1.ip.txt
lookup-main.bat
cd C:\Program Files\WAMP\www\openaudit\scripts\scans for /F %%i in (subnets.txt) do lookup-subnet.bat %%i
lookup-subnet.bat
@echo off cd C:\Program Files\WAMP\www\openaudit\scripts\scans del %1.host.txt for /F %%i in (%1.ip.txt) do @lookup-backend.bat %%i >> %1.host.txt
lookup-backend.bat
@nslookup %1 | "C:\program files\utilities\bin\grep" "Name: " | "C:\program files\utilities\bin\awk" -F " " "{print $2}"
insert-hosts-main.bat
@echo off cd C:\Program Files\WAMP\www\openaudit\scripts\scans for /F %%i in (subnets.txt) do insert-hosts-subnet.bat %%i
insert-hosts-subnet.bat
@echo off cd C:\Program Files\WAMP\www\openaudit\scripts\scans for /F %%i in (%1.host.txt) do @insert-hosts-parse.bat %%i
insert-hosts-parse.bat
@echo off cd C:\Program Files\WAMP\www\openaudit\scripts\scans echo %1 | "C:\Program Files\Utilities\bin\awk.exe" -F "." "{print $1}" > temp-out-insert.txt for /F %%A in (temp-out-insert.txt) do @insert-hosts-backend.bat %%A del temp-out-insert.txt
insert-hosts-backend.bat
cd C:\Program Files\WAMP\www\openaudit\scripts\scans "C:\Program Files\Utilities\bin\wget.exe" "http://camgmt01/openaudit/launch_local_audit.php?domain=example.org&application=cmd&ext=vbs&hostname=%1&" -O %1.vbs cscript %1.vbs del %1.vbs
subnet.txt (代码片段)
10.14.8.0-255 10.14.9.0-255
使用 MySQL 获取所有 Windows 服务器
select system_uuid,system_name,net_ip_address,system_os_name from openaudit.system where system_os_name like '%Microsoft%Server%';
exchangeservers 主机组
select distinct tbl_host.host_name,tbl_host.address from tbl_host,tbl_lnkHostgroupToHost,tbl_hostgroup where tbl_hostgroup.hostgroup_name = 'exchangeservers' and tbl_lnkHostgroupToHost.idMaster = tbl_hostgroup.id and tbl_lnkHostgroupToHost.idSlave = tbl_host.id;
sqlservers 主机组
select distinct tbl_host.host_name,tbl_host.address from tbl_host,tbl_lnkHostgroupToHost,tbl_hostgroup where tbl_hostgroup.hostgroup_name = 'sqlservers' and tbl_lnkHostgroupToHost.idMaster = tbl_hostgroup.id and tbl_lnkHostgroupToHost.idSlave = tbl_host.id;
lotusnotesservers 主机组
select distinct tbl_host.host_name,tbl_host.address from tbl_host,tbl_lnkHostgroupToHost,tbl_hostgroup where tbl_hostgroup.hostgroup_name = 'lotusnotesservers' and tbl_lnkHostgroupToHost.idMaster = tbl_hostgroup.id and tbl_lnkHostgroupToHost.idSlave = tbl_host.id;
windowsservers 主机组
select distinct tbl_host.host_name,tbl_host.address from tbl_host,tbl_lnkHostgroupToHost,tbl_hostgroup where tbl_hostgroup.hostgroup_name = 'windowsservers' and tbl_lnkHostgroupToHost.idMaster = tbl_hostgroup.id and tbl_lnkHostgroupToHost.idSlave = tbl_host.id;
OpenAudit 查询
Exchange
select distinct system.system_name,system.net_ip_address from system,software where software_name like '%icrosoft%xchange' and software.software_uuid = system.system_uuid;
SQL
select distinct system.system_name,system.net_ip_address from system,software where software.software_name like '%icrosoft%SQL%erver%200%' and system.system_os_name like '%erver%' and software.software_uuid = system.system_uuid;
Lotus Domino
select distinct system.system_name,system.net_ip_address from system,software where software_name like '%otus%omino%' and software.software_uuid = system.system_uuid;
Windows
select distinct system.system_name,system.net_ip_address from system where system.system_os_name like '%microsoft%server%';
参见
- Inotifyd:用于监控目录或文件更改或用于后处理。