Never let your sense of morals prevent you from doing what is right.

19,863 点击次数

分类: AIX

  • How to configure the SNMP protocol of AIX

    How to configure the SNMP protocol of AIX

    1, Configuring the SNMP Agent in the AIX

    1×1 Check the current running SNMP version

    ls -l /usr/sbin/snmpd*
    AIX SNMP

    You can see that the current snmpd is using snmpdv3ne, which means that it supports the non-encrypted version of SNMPv3, ne=no encryption, as long as /etc/snmpdv3.conf is configured, it can be used in the way of SNMPv1, so the default version can meet the requirements, if there are special needs, you can also change the version with snmpv3_ssw command.

    Switch to SNMPv1

    snmpv3_ssw -1

    Switching to SNMPv3 non-encrypted version

    snmpv3_ssw -n

    Switch to the encrypted version of SNMPv3 (this version is not installed by default)

    snmpv3_ssw -e

    1×2 Create a community called hmsnmp

    Modify the /etc/snmpdv3.conf file as shown below, taking special care to mark the sections with red lines.

    Where 192.0.243.113 is the IP address of the monitoring tool, indicating that only this IP is allowed to access SNMP of AIX, for security reasons.

    1×3 Stop and start the service to make changes to /etc/snmpdv3.conf effective

    stopsrc -s aixmibd
    stopsrc -s snmpmibd
    stopsrc -s hostmibd
    stopsrc -s snmpd
    startsrc -s snmpd
    startsrc -s hostmibd -a "-c hmsnmp"
    startsrc -s snmpmibd -a "-c hmsnmp"
    startsrc -s aixmibd -a "-c hmsnmp"

    It is important to note that when the operating system reboots, the default boot parameters are public community, so in order to make the hmsnmp community work properly after the reboot, it is recommended to modify the /etc/rc.tcpip file to modify the default boot parameters as follows.

    Start up the hostmibd daemon

    start /usr/sbin/hostmibd "$src_running" "-c hmsnmp "

    Start up the snmpmibd daemon

    start /usr/sbin/snmpmibd "$src_running" "-c hmsnmp "

    Start up the aixmibd daemon

    start /usr/sbin/aixmibd "$src_running" "-c hmsnmp "

    1×4 testing for normal SNMP service

    Execute the following commands locally:

    # snmpinfo -md -c hmsnmp sysDescr
    
    1.3.6.1.2.1.1.1.0 = "IBM PowerPC CHRP Computer
    Machine Type: 0x0800004c Processor id: 00F7TEST4C00
    Base Operating System Runtime AIX version: 06.01.0007.0015
    TCP/IP Client Support version: 06.01.0007.0016"

    On other machines where SNMPWALK is installed the following commands can be executed for verification.

    # snmpwalk -v 1 -c hmsnmp 192.0.246.23 1.3.6.1.2.1.1.1.0
    
    SNMPv2-MIB::sysDescr.0 = STRING: IBM PowerPC CHRP Computer
    Machine Type: 0x0800004c Processor id: 00F7TEST4C00
    Base Operating System Runtime AIX version: 06.01.0007.0015
    TCP/IP Client Support version: 06.01.0007.0016

    2, MIB OID commonly used in AIX
    Above, we configured the value of SNMP Community: hmsnmp, which can be used to monitor SNMP-related services of the tool.
    If you need to find the OID of an object, you can go to /etc/mib.defs to find the corresponding object, and then snmpinfo -md ObjectName to get the corresponding OID for remote call.

    2×1 Display CPU usage

    # snmpinfo -md -v -c hmsnmp aixSeCPUUtilization
    
    aixSeCPUUtilization.0 = 5

    Remove the -v parameter and you see the OID value.

    # snmpinfo -md -c hmsnmp aixSeCPUUtilization
    
    1.3.6.1.4.1.2.6.191.1.2.1.0 = 5

    2×2 Show Paging Space

    # snmpinfo -md -v -c hmsnmp aixPagingSpace
    
    aixPageThreshold.0 = 95
    aixPageName.1 = "hd6"
    aixPageNameVG.1 = "rootvg"
    aixPageNamePV.1 = "hdisk0"
    aixPageSize.1 = 14336
    aixPagePercentUsed.1 = 1
    aixPageStatus.1 = 1
    aixPageType.1 = 1
    aixPageIndex.1 = 1

    2×3 View the serial number of the machine

    # snmpinfo -md -v -c hmsnmp aixSeMachineType
    
    aixSeMachineType.0 = "IBM,8205-E6C"
    
    # snmpinfo -md -v -c hmsnmp aixSeSerialNumber
    
    aixSeSerialNumber.0 = "IBM,0210TESTR"

    2×4 View CPU count

    # snmpinfo -md -v -c hmsnmp aixSeNumCPUs
    
    aixSeNumCPUs.0 = 4

    2×5 View VG-related information: aixVolumeGroup

    2×6 View LV-related information: aixLogicalVolume

    2×7 View PV-related information: aixPhysicalVolume

    2×8 View FS-related information: aixFileSystem

    3, A simple case of system monitoring via SNMP

    If you are just doing a simple monitoring, then you can write your own shell script.

    Let’s write a shell script, AIX_FS_CHECK.sh, which is deployed on the monitor, using the usage of the monitor file system as an example.

    In order to see the actual output, we set the threshold to a low value in the script, if you are interested, you can also bring the threshold as a parameter in the script.

    # . /AIX_FS_CHECK.sh -h 192.0.246.23 -c hmsnmp
    
    WARNING!!! /usr used 74%
    WARNING!!! /usr Inodes used 18%
    WARNING!!! /patch used 97%

    The monitor smoothly gets the information of the monitored device through SNMP and sends the relevant alarm information according to our request.

    4, Summary

    This article introduces the method of monitoring AIX system using SNMP protocol. Although there is still a long way to realize the monitoring of various indicators, flexibility and ease of use should be improved, but it provides a way of thinking to realize the monitoring of the operating system in an agentless way, I hope to bring some help to those who need it.

    5, Additional

    Alternatively, there is another way to use the conf file I provided directly, which of course requires you to modify the community and IP address.

    5×1 Stop service.

    stopsrc -s snmpd

    5×2 Modify the conf file, replace the original conf file, and remember to back it up before replacing it.

    5×3 Start service.

    startsrc -s snmpd

    snmpd.conf content:

    ###############################################################################
    #
    # EXAMPLE.conf:
    #   An example configuration file for configuring the Net-SNMP agent ('snmpd')
    #   See the 'snmpd.conf(5)' man page for details
    #
    #  Some entries are deliberately commented out, and will need to be explicitly activated
    #
    ###############################################################################
    #
    #  AGENT BEHAVIOUR
    #
    
    #  Listen for connections from the local system only
    #agentAddress  udp:127.0.0.1:161
    #  Listen for connections on all interfaces (both IPv4 *and* IPv6)
    agentAddress udp:161,udp6:[::1]:161
    
    
    
    ###############################################################################
    #
    #  SNMPv3 AUTHENTICATION
    #
    #  Note that these particular settings don't actually belong here.
    #  They should be copied to the file /var/net-snmp/snmpd.conf
    #     and the passwords changed, before being uncommented in that file *only*.
    #  Then restart the agent
    
    #  createUser authOnlyUser  MD5 "remember to change this password"
    #  createUser authPrivUser  SHA "remember to change this one too"  DES
    #  createUser internalUser  MD5 "this is only ever used internally, but still change the password"
    
    #  If you also change the usernames (which might be sensible),
    #  then remember to update the other occurances in this example config file to match.
    
    
    
    ###############################################################################
                                                     #     Remember to activate the 'createUser' lines above
    #  ACCESS CONTROL
    #
    
                                                     #  Default access to basic system info
    view systemonly internet                    - included -
    view systemonly 1.3.6.1.4.1.2               - included -
    view systemonly 1.3.6.1.4.1.2.2             - included -
    view systemonly 1.3.6.1.4.1.2.3             - included -
    view systemonly 1.3.6.1.4.1.2.5             - included -
    view systemonly 1.3.6.1.4.1.2.6             - included -
    view systemonly directory                   - included -
    view systemonly mgmt                        - included -
    view systemonly mib-2                       - included -
    view systemonly system                      - included -
    view systemonly aix                         - included -
    view systemonly 1.3.6.1.4                   - included -
    view systemonly 1.3.6.1.6                   - included -
    view systemonly 1.3.6.1.6.3.1.1.5           - included -
    view systemonly 1.3.6.1.4.1.2021            - included -
    view systemonly 1.3.6.1.4.1.2.3.1.2.2.2.1.4 - included -
    
    # Include aixmibd managed MIBS with this view
    view systemonly 1.3.6.1.4.1.2.6.191         - included -
    
    #view   systemonly  included   .1.3.6
    #view   systemonly  included   .1.3.6.1.4.1.2021.10.1.3.1
    #view   systemonly  included   .1.3.6.1.4.1.2021.11.9.0
    #view   systemonly  included   .1.3.6.1.4.1.2021.11.11.0
    #view   systemonly  included   .1.3.6.1.4.1.2021.9
    #view   systemonly  included   .1.3.6.1.2.3.1.2.1.2
    #view   systemonly  included   .1.3.6.1.4.1.2.3.1.2.2.1.1.2
    #view   systemonly  included   .1.3.6.1.2.1.1
    #view   systemonly  included   .1.3.6.1.2.1.25.1
    
                                                     #  Full access from the local host
    #rocommunity public  localhost
                                                     #  Default access to basic system info
    # rocommunity public  default    -V systemonly
    rocommunity public
    
                                                     #  Full access from an example network
                                                     #     Adjust this network address to match your local
                                                     #     settings, change the community string,
                                                     #     and check the 'agentAddress' setting above
    #rocommunity secret  10.0.0.0/16
    
                                                     #  Full read-only access for SNMPv3
     rouser   authOnlyUser
                                                     #  Full write access for encrypted requests
                                                     #     Remember to activate the 'createUser' lines above
    #rwuser   authPrivUser   priv
    
    #  It's no longer typically necessary to use the full 'com2sec/group/access' configuration
    #  r[ou]user and r[ow]community, together with suitable views, should cover most requirements
    
    
    
    ###############################################################################
    #
    #  SYSTEM INFORMATION
    #
    
    #  Note that setting these values here, results in the corresponding MIB objects being 'read-only'
    #  See snmpd.conf(5) for more details
    sysLocation    Sitting on the Dock of the Bay
    sysContact     Me <me@example.org>
                                                     # Application + End-to-End layers
    sysServices    72
    
    
    #
    #  Process Monitoring
    #
                                   # At least one  'mountd' process
    proc  mountd
                                   # No more than 4 'ntalkd' processes - 0 is OK
    proc  ntalkd    4
                                   # At least one 'sendmail' process, but no more than 10
    proc  sendmail 10 1
    
    #  Walk the UCD-SNMP-MIB::prTable to see the resulting output
    #  Note that this table will be empty if there are no "proc" entries in the snmpd.conf file
    
    
    #
    #  Disk Monitoring
    #
                                   # 10MBs required on root disk, 5% free on /var, 10% free on all other disks
    disk       /     10000
    disk       /var  5%
    disk       /usr  10000
    includeAllDisks  10%
    
    #  Walk the UCD-SNMP-MIB::dskTable to see the resulting output
    #  Note that this table will be empty if there are no "disk" entries in the snmpd.conf file
    
    
    #
    #  System Load
    #
                                   # Unacceptable 1-, 5-, and 15-minute load averages
    load   12 10 5
    
    #  Walk the UCD-SNMP-MIB::laTable to see the resulting output
    #  Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file
    
    
    
    ###############################################################################
    #
    #  ACTIVE MONITORING
    #
    
                                        #   send SNMPv1  traps
     trapsink     localhost public
                                        #   send SNMPv2c traps
    #trap2sink    localhost public
                                        #   send SNMPv2c INFORMs
    #informsink   localhost public
    
    #  Note that you typically only want *one* of these three lines
    #  Uncommenting two (or all three) will result in multiple copies of each notification.
    
    
    #
    #  Event MIB - automatically generate alerts
    #
                                       # Remember to activate the 'createUser' lines above
    iquerySecName   internalUser       
    rouser          internalUser
                                       # generate traps on UCD error conditions
    defaultMonitors          yes
                                       # generate traps on linkUp/Down
    linkUpDownNotifications  yes
    
    
    
    ###############################################################################
    #
    #  EXTENDING THE AGENT
    #
    
    #
    #  Arbitrary extension commands
    #
     extend    test1   /bin/echo  Hello, world!
     extend-sh test2   echo Hello, world! ; echo Hi there ; exit 35
    #extend-sh test3   /bin/sh /tmp/shtest
    
    #  Note that this last entry requires the script '/tmp/shtest' to be created first,
    #    containing the same three shell commands, before the line is uncommented
    
    #  Walk the NET-SNMP-EXTEND-MIB tables (nsExtendConfigTable, nsExtendOutput1Table
    #     and nsExtendOutput2Table) to see the resulting output
    
    #  Note that the "extend" directive supercedes the previous "exec" and "sh" directives
    #  However, walking the UCD-SNMP-MIB::extTable should still returns the same output,
    #     as well as the fuller results in the above tables.
    
    
    #
    #  "Pass-through" MIB extension command
    #
    #pass .1.3.6.1.4.1.8072.2.255  /bin/sh       PREFIX/local/passtest
    #pass .1.3.6.1.4.1.8072.2.255  /usr/bin/perl PREFIX/local/passtest.pl
    
    # Note that this requires one of the two 'passtest' scripts to be installed first,
    #    before the appropriate line is uncommented.
    # These scripts can be found in the 'local' directory of the source distribution,
    #     and are not installed automatically.
    
    #  Walk the NET-SNMP-PASS-MIB::netSnmpPassExamples subtree to see the resulting output
    
    
    #
    #  AgentX Sub-agents
    #
                                               #  Run as an AgentX master agent
     master          agentx
                                               #  Listen for network connections (from localhost)
                                               #    rather than the default named socket /var/agentx/master
    #agentXSocket    tcp:localhost:705
    
    #proxy -v 1 -c public 127.0.0.1:1610 .1.3.6.1.4.1.2021.9
  • IBM AIX的SNMP协议配置步骤

    I found that a lot of people from English as a first language countries read this article, but many left at the sight of it being in Chinese, so to be able to help users worldwide, if you need to read the English version, please jump to the following link:

    How to configure the SNMP protocol of AIX


    一、配置AIX下SNMP代理程序

    1、查看当前运行的snmp版本

    可以看到当前snmpd使用的是snmpdv3ne,表示支持的是SNMPv3非加密版本,ne=no encryption(非加密),只要对/etc/snmpdv3.conf进行相关配置,就能够以SNMPv1的方式使用,因此一般默认使用这个版本都能满足要求,如果有特殊需要也可用snmpv3_ssw命令来更改版本:

    切换至SNMPv1

    snmpv3_ssw -1

    切换至SNMPv3非加密版本

    snmpv3_ssw -n

    切换至SNMPv3的加密版本(该版本默认并未安装)

    snmpv3_ssw -e

    2、创建一个叫hmsnmp的community

    修改/etc/snmpdv3.conf文件如下所示,请特别注意用红线标注部分的内容。

    其中192.0.243.113是监控机的地址,就是安装监控软件的那台设备地址,根据需要进行修改,表示只对该IP开放本机的snmp服务,这是出于安全性的考虑。

    3、停止并启动相关服务,使得对/etc/snmpdv3.conf的修改生效

    stopsrc -s aixmibd

    stopsrc -s snmpmibd

    stopsrc -s hostmibd

    stopsrc -s snmpd

    startsrc -s snmpd

    startsrc -s hostmibd -a “-c hmsnmp”

    startsrc -s snmpmibd -a “-c hmsnmp”

    startsrc -s aixmibd -a “-c hmsnmp”

    这里需要注意的是,当操作系统重启后,由于默认情况下是按照public的community去启动的,因此为了使得重启后hmsnmp的community能正常工作,建议修改/etc/rc.tcpip文件,修改默认的启动参数,如下所示:

    # Start up the hostmibd daemon

    start /usr/sbin/hostmibd “$src_running” “-c hmsnmp ”

    # Start up the snmpmibd daemon

    start /usr/sbin/snmpmibd “$src_running” “-c hmsnmp ”

    # Start up the aixmibd daemon

    start /usr/sbin/aixmibd “$src_running” “-c hmsnmp ”

    4、测试snmp服务是否正常

    在本机可执行命令如下:

    # snmpinfo -md -c hmsnmp sysDescr

    1.3.6.1.2.1.1.1.0 = “IBM PowerPC CHRP Computer

    Machine Type: 0x0800004c Processor id: 00F7TEST4C00

    Base Operating System Runtime AIX version: 06.01.0007.0015

    TCP/IP Client Support version: 06.01.0007.0016″

    在监控机可执行命令如下:

    # snmpwalk -v 1 -c hmsnmp  192.0.246.23  1.3.6.1.2.1.1.1.0

    SNMPv2-MIB::sysDescr.0 = STRING: IBM PowerPC CHRP Computer

    Machine Type: 0x0800004c Processor id: 00F7TEST4C00

    Base Operating System Runtime AIX version: 06.01.0007.0015

    TCP/IP Client Support version: 06.01.0007.0016

    二、AIX常用的MIB OID
    上面我们主要完成的工作是配置了一个community叫hmsnmp,可用于监控机调用snmp相关服务,接下去给大家一些常用的MIB库信息,特别是OID,供参考。
    AIX系统的常见基本信息的MIB为”AIX”打头,如果需要查找对于对象的OID,可以先到/etc/mib.defs中找到相应的对象,然后通过snmpinfo -md ObjectName,获取对应的OID,用于远程调用。

    1、显示CPU使用率

    # snmpinfo -md -v -c hmsnmp aixSeCPUUtilization

    aixSeCPUUtilization.0 = 5

    去掉-v参数看到的就是OID值

    # snmpinfo -md -c hmsnmp aixSeCPUUtilization

    1.3.6.1.4.1.2.6.191.1.2.1.0 = 5

    2、显示Paging Space

    # snmpinfo -md -v -c hmsnmp aixPagingSpace

    aixPageThreshold.0 = 95

    aixPageName.1 = “hd6”

    aixPageNameVG.1 = “rootvg”

    aixPageNamePV.1 = “hdisk0”

    aixPageSize.1 = 14336

    aixPagePercentUsed.1 = 1

    aixPageStatus.1 = 1

    aixPageType.1 = 1

    aixPageIndex.1 = 1

    3、查看机器的序列号

    # snmpinfo -md -v -c hmsnmp aixSeMachineType

    aixSeMachineType.0 = “IBM,8205-E6C”

    # snmpinfo -md -v -c hmsnmp aixSeSerialNumber

    aixSeSerialNumber.0 = “IBM,0210TESTR”

    4、查看CPU数量

    # snmpinfo -md -v -c hmsnmp aixSeNumCPUs

    aixSeNumCPUs.0 = 4

    5、查看VG相关信息aixVolumeGroup

    6、查看LV相关信息aixLogicalVolume

    7、查看PV相关信息aixPhysicalVolume

    8、查看FS相关信息aixFileSystem

    三、通过SNMP进行系统监控的简单案例

    配置好需要使用的snmp agent的community名称,了解清楚需要监控对象的OID值,接下去就只要在监控机上部署对应的监控软件来调用snmp就可以了,例如SolarWinds。如果只是做一个简单监控,那自己写shell脚本也不失为一种方法。

    下面我们就以监控文件系统的使用率为例,来自己编写一个shell脚本AIX_FS_CHECK.sh,该脚本部署到监控机上。

    为了观察实际输出效果,在脚本中我们将阀值设置的比较低,如果你有兴趣也可以把阀值作为一个参数带入到脚本中,我们来执行以下脚本看看效果:

    # ./AIX_FS_CHECK.sh -h 192.0.246.23 -c hmsnmp

    WARNING!!/usr used 74%

    WARNING!!/usr Inodes used 18%

    WARNING!!/patch used 97%

    监控机通过snmp顺利的获取到了被监控设备的信息,并根据我们的要求发出相关报警信息。

    四、小结

    本文介绍了使用SNMP协议对AIX系统进行监控的方法,虽然距离实现多种指标监控仍有着较大的距离,灵活性和易用性也有待提高,但为实现操作系统无代理方式的监控提供了一种思路,希望能给有需要的朋友带来一些帮助。