2.10.11 Example of extended MIB object definition
Now, let us define extended MIB objects. The procedure for defining extended MIB objects consists of the following steps:
-
Defining MIB objects
-
Logging in to the system (flintagent in this example)
-
Creating an /etc/SnmpAgent.d/snmpd.extend file
- Organization of this subsection
(1) Defining MIB objects
Suppose, for example, that you work for the Flintstones Company. Your goal is to define MIB objects so that you can:
-
list users who are using the system
-
reference the contents of memory on each machine
-
manage mail queues
-
manage the number of widgets produced per hour on an unattended system
-
keep track of the LP scheduler
-
reference the default printer
-
reference the user IDs, the amount of disk space used by each user, and the users' e-mail address list
-
list root processes
-
modify the inetd(1M)'s configuration file
For details about defining the above MIB objects, see the description of MIB object definition in 2.10.11(3) Creating an /etc/SnmpAgent.d/snmpd.extend file.
Your agent system is flintagent with the default community name public. The set community name is secret. To ensure that your object IDs are unique, you decide to define your MIB objects in the flintstones (4242) subtree. The MIB tree for this example has the following layers. The following shows the structure of this MIB tree.
iso (1) ::= { 1 } org (3) ::= { 3 } dod (6) ::= { 6 } internet (1) OBJECT IDENTIFIER ::= { dod 1 } private (4) OBJECT IDENTIFIER ::= { internet 4 } enterprises (1) OBJECT IDENTIFIER ::= { private 1 } flintstones (4242) OBJECT IDENTIFIER ::= { enterprises 4242 } fsys (1) OBJECT IDENTIFIER ::= { flintstones 1 } fmail (2) OBJECT IDENTIFIER ::= { flintstones 2 } fwidgets (3) OBJECT IDENTIFIER ::= { flintstones 3 } fprinters (4) OBJECT IDENTIFIER ::= { flintstones 4 } fdisk(5) OBJECT IDENTIFIER ::= { flintstones 5 } fprocess(6) OBJECT IDENTIFIER ::= { flintstones 6 } fconfig(7) OBJECT IDENTIFIER ::= { flintstones 7 }
The following figure illustrates the structure of the MIB tree.
Each leaf node has one object identifier as shown below.
Leaf node Object identifier fsysUsers 1.3.6.1.4.1.4242.1.1.0 fmemory 1.3.6.1.4.1.4242.1.2.0 fmailNumMsgs 1.3.6.1.4.1.4242.2.1.0 fmailListMsgs 1.3.6.1.4.1.4242.2.2.0 fwidgetsPerHour 1.3.6.1.4.1.4242.3.1.0 fprintersStatus 1.3.6.1.4.1.4242.4.1.0 fdefaultPrinter 1.3.6.1.4.1.4242.4.2.0 fUID 1.3.6.1.4.1.4242.5.1.1.1.fUID#1 fUserName 1.3.6.1.4.1.4242.5.1.1.2.fUID fUserDiskSpace 1.3.6.1.4.1.4242.5.1.1.3.fUID fUserEmailAddress 1.3.6.1.4.1.4242.5.1.1.4.fUID fProcessID 1.3.6.1.4.1.4242.6.1.1.1.fProcessID#2 fProcessName 1.3.6.1.4.1.4242.6.1.1.2.fProcessID fInetdConf 1.3.6.1.4.1.4242.7.1.0
#1: FUID value
#2: fProcessID value
(2) Log in as a root user to the flintagent system
Log in to the flintagent system as a root user.
(3) Creating an /etc/SnmpAgent.d/snmpd.extend file
This subsection presents an example of creating an /etc/SnmpAgent.d/snmpd.extend file.
The contents of the sample file /etc/SnmpAgent.d/snmpd.extend are provided in the sample extended MIB definition file /opt/OV/prg_samples/eagent/snmpd.extend.
FLINTSTONES-MIB DEFINITIONS ::= BEGIN -- -- Test MIB- used for testing snmpd.ea(extensible agent) -- -- internet OBJECT IDENTIFIER ::= { iso(1) org(3) dod(6) internet(1) } enterprises OBJECT IDENTIFIER ::= { internet private(4) 1 } flintstones OBJECT IDENTIFIER ::= { enterprises 4242 } fsys OBJECT IDENTIFIER ::= { flintstones 1 } fmail OBJECT IDENTIFIER ::= { flintstones 2 } fwidgets OBJECT IDENTIFIER ::= { flintstones 3 } fprinters OBJECT IDENTIFIER ::= { flintstones 4 } fdisk OBJECT IDENTIFIER ::= { flintstones 5 } fprocess OBJECT IDENTIFIER ::= { flintstones 6 } fconfig OBJECT IDENTIFIER ::= { flintstones 7 } fsysUsers OBJECT-TYPE SYNTAX DisplayString ACCESS read-only STATUS mandatory DESCRIPTION "List of users on the flintstone machine READ-COMMAND: /usr/bin/users; exit 0 READ-COMMAND-TIMEOUT: 5" ::= { fsys 1 } fmemory OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Amount of memory (in megabytes) on system APPEND-COMMUNITY-NAME: true FILE-NAME: /opt/OV/prg_samples/eagent/memory" ::= { fsys 2 } fmailNumMsgs OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Message count on the mail queue. READ-COMMAND: /usr/bin/mailq | fgrep -v Mail | wc -l" ::= { fmail 1 } fmailListMsgs OBJECT-TYPE SYNTAX DisplayString ACCESS read-only STATUS mandatory DESCRIPTION "List of messages on the mail queue. READ-COMMAND: /usr/bin/mailq READ-COMMAND-TIMEOUT: 10" ::= { fmail 2 } fwidgetsPerHour OBJECT-TYPE SYNTAX Gauge ACCESS read-write STATUS mandatory DESCRIPTION "Number of widgets produced per hour. READ-COMMAND: /opt/OV/prg_samples/eagent/num_widgets $i $c $o $s READ-COMMAND-TIMEOUT: 2 WRITE-COMMAND: /opt/OV/prg_samples/eagent/change_num_widgets $* WRITE-COMMAND-TIMEOUT: 10" ::= { fwidgets 1 } fprintersStatus OBJECT-TYPE SYNTAX INTEGER { up(1), down(2) } ACCESS read-only STATUS mandatory DESCRIPTION "Status of printer scheduler. READ-COMMAND: ps -ef|grep lpsched | grep -v grep |wc | awk '{ if ($1 == 0) print 2; else print 1 }'" ::= { fprinters 1 } fdefaultPrinter OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "Default printer FILE-NAME: /usr/spool/lp/default" ::= { fprinters 2 } fUserDiskTable OBJECT-TYPE SYNTAX SEQUENCE OF FuserDiskEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "List of users and the number of kilobytes in their home directory. FILE-NAME: /opt/OV/prg_samples/eagent/user_disk_space" ::= { fdisk 1 } fUserDiskEntry OBJECT-TYPE ACCESS not-accessible SYNTAX FuserDiskEntry STATUS mandatory DESCRIPTION "This macro documents the column that uniquely describes each row." INDEX { fUID } ::= { fUserDiskTable 1 } FUserDiskEntry ::= SEQUENCE { fUID INTEGER, fUserName DisplayString, fUserDiskSpace INTEGER, fUserEmailAddress DisplayString } fUID OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "User's unique ID" ::= { fUserDiskEntry 1 } fUserName OBJECT-TYPE SYNTAX DisplayString ACCESS read-only STATUS mandatory DESCRIPTION "User login name" ::= { fUserDiskEntry 2 } fUserDiskSpace OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Amount of disk space (in kilobytes) used by the user." ::= { fUserDiskEntry 3 } fUserEmailAddress OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "Email address for the user" ::= { fUserDiskEntry 4 } fUserRootProcessTable OBJECT-TYPE SYNTAX SEQUENCE OF FuserRootProcessEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "List of root processes. Do not execute command more than every 60 seconds. FILE-COMMAND: /opt/OV/prg_samples/eagent/get_processes FILE-COMMAND-FREQUENCY: 60 FILE-NAME: /opt/OV/prg_samples/eagent/root_processes" ::= { fprocess 1 } fUserRootProcessEntry OBJECT-TYPE SYNTAX FuserRootProcessEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "This macro documents the column that uniquely describes each row." INDEX { fProcessID } ::= { fUserRootProcessTable 1 } FUserRootProcessEntry ::= SEQUENCE { fProcessID INTEGER, fProcessName DisplayString } fProcessID OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Process ID" ::= { fUserRootProcessEntry 1 } fProcessName OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "Name of process" ::= { fUserRootProcessEntry 2 } fInetdConf OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "The configuration file for inetd FILE-COMMAND: /opt/OV/prg_samples/eagent/update_inetd $r FILE-COMMAND-FREQUENCY: 7200 FILE-NAME: /etc/inetd.conf" ::= { fconfig 1 } END
This subsection describes each MIB object definition that is included in the example of creating an /etc/SnmpAgent.d/snmpd.extend file.
Procedure
-
List users who are using the system
You can configure SNMP Agent to execute a command when it receives a GetRequest from a manager. To do so, specify the command to be executed after the READ-COMMAND label. For example, the following code fragment makes SNMP Agent execute the /usr/bin/users command to obtain a list of users on the system as a MIB value:
fsysUsers OBJECT-TYPE SYNTAX DisplayString ACCESS read-only STATUS mandatory DESCRIPTION "List of users on the flintstone machine READ-COMMAND: /usr/bin/users; exit 0 READ-COMMAND-TIMEOUT: 5" ::= { fsys 1 }
When SNMP Agent receives from a manager a GetRequest with object identifier flintstones.fsys.fsysUsers.0 specified, SNMP Agent executes the /usr/bin/users command (specified after the READ-COMMAND label) and returns the result to the manager.
By default, SNMP Agent returns a genErr error to the manager if the command specified after the READ-COMMAND label does not return a response within 3 seconds. You can change this command completion wait time to any value by using the READ-COMMAND-TIMEOUT label. If, for example, you want to change the command completion wait time to 5 seconds, write the following READ-COMMAND-TIMEOUT line:
READ-COMMAND-TIMEOUT: 5
-
Reference the contents of memory on each machine
You can use the Extensible SNMP Agent to create a proxy. The agent can respond to objects on behalf of another system, device, or application.
For example, if you want the agent to respond with the amount of memory for three systems that do not support SNMP, the agent can act as a proxy for those other systems. The three systems that do not support SNMP are named larry, curly, and moe. The following three files contain the amount of memory on each system:
/opt/OV/prg_samples/eagent/memory.larry /opt/OV/prg_samples/eagent/memory.curly /opt/OV/prg_samples/eagent/memory.moe
To implement this proxy, you would define the following object:
fmemory OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Amount of memory (in megabytes) on system APPEND-COMMUNITY-NAME: true FILE-NAME: /opt/OV/prg_samples/eagent/memory" ::= { fsys 2 }
The agent will respond on behalf of larry, curly, and moe for the object flintstones.fsys.fmemory. The community name in the request indicates the system of interest. Suppose that SNMP Agent receives a GetRequest for the object with object identifier flintstones.fsys.fmemory.0 and that the community name specified in this request is moe. In this case, SNMP Agent reads /opt/OV/prg_samples/eagent/memory.moe and returns the value in the file to the manager. As shown in the code sample, you must specify APPEND-COMMUNITY-NAME: true to use SNMP Agent as a proxy. If you specify APPEND-COMMUNITY-NAME: true, SNMP Agent reads or writes the file whose file name is file_name followed by the community name specified in the request (in this example, the resulting file name is /opt/OV/prg_samples/eagent/memory.community-name). You can also set SNMP Agent so that it acts as a proxy for an object (for example, a MIB object) that already exists on SNMP Agent. The example below shows how to make proxy machines larry, curly, and moe return their own sysDescr value. Each proxy machine has its own sysDescr value in the following file:
If SNMP Agent receives from a manager a GetRequest for the object with object identifier system.sysDescr.0 and the community name specified in this request is public, SNMP Agent returns the sysDescr value of the MIB object.
/opt/OV/prg_samples/eagent/sysDescr.larry /opt/OV/prg_samples/eagent/sysDescr.curly /opt/OV/prg_samples/eagent/sysDescr.moe
To implement this proxy, you would define the following object:
sysDescr OBJECT-TYPE SYNTAX DisplayString (SIZE(0..255)) ACCESS read-only STATUS mandatory DESCRIPTION "A textual description of the entity. This value should include the full name and version identification of the system's hardware type, software operating-system, and networking software. It is mandatory that this only contain printable ASCII characters. APPEND-COMMUNITY-NAME : true FILE-NAME: /opt/OV/prg_samples/eagent/sysDescr" ::= { system 1 }
If SNMP agent receives a GetRequest for the object ID system.sysDescr.0 with community name moe from the manager, SNMP Agent reads /opt/OV/prg_samples/eagent/sysDescr.moe and returns the contents of the file to the manager. If SNMP Agent receives a GetRequest for the object ID system.sysDescr.0 with community name public from the manager, SNMP Agent returns the sysDescr value of the MIB object.
-
Manage the mail queue
The example below shows how to specify the READ-COMMAND line to manage the mail queue.
fmailNumMsgs OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Message count on the mail queue. READ-COMMAND: /usr/bin/mailq | fgrep -v Mail |wc -l" ::= { fmail 1 } fmailListMsgs OBJECT-TYPE SYNTAX DisplayString ACCESS read-only STATUS mandatory DESCRIPTION "List of messages on the mail queue. READ-COMMAND: /usr/bin/mailq READ-COMMAND-TIMEOUT: 10" ::= { fmail 2 }
-
Control the number of widgets that the system produces per hour while unattended
You can configure SNMP Agent to execute a command when it receives a SetRequest from a manager. To do so, specify the command to be executed after the WRITE-COMMAND label.
For example, to use the /opt/OV/prg_samples/eagent/change_num_widgets command to change the number of widgets that the system produces per hour while unattended, specify the following:
fwidgetsPerHour OBJECT-TYPE SYNTAX Gauge ACCESS read-write STATUS mandatory DESCRIPTION "Number of widgets produced per hour. READ-COMMAND: /opt/OV/prg_samples/eagent /num_widgets $i $c $o $s READ-COMMAND-TIMEOUT: 2 WRITE-COMMAND: /opt/OV/prg_samples/eagent /change_num_widgets $* WRITE-COMMAND-TIMEOUT: 10" ::= { fwidgets 1 }
You can pass arguments to the commands you specified after the READ-COMMAND and WRITE-COMMAND label. To do so, specify the arguments after the command name. For the meanings of the arguments, see the argument descriptions in 2.10.3(2) Writing a script or program.
-
Keep track of the LP scheduler
The example below shows how to specify the READ-COMMAND line to monitor the status of the LP scheduler.
fprintersStatus OBJECT-TYPE SYNTAX INTEGER { up(1), down(2) } ACCESS read-only STATUS mandatory DESCRIPTION "Status of printer scheduler. READ-COMMAND: ps -ef|grep lpsched | grep -v grep | wc | awk '{ if ($1 == 0) print 2; else print 1}'" := { fprinters 1 }
-
Reference the default printer
You can configure SNMP Agent to create an extended MIB object using a file as source of the MIB value. To do so, specify the name of the file after the FILE-NAME label.
To create an object that reads the /usr/spool/lp/default file to reference the default printer, specify the following:
fdefaultPrinter OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "Default printer FILE-NAME: /usr/spool/lp/default" ::= { fprinters 2 }
When SNMP Agent receives from a manager a GetRequest for the object with object identifier flintstones.fprinters.fdefaultPrinter.0, SNMP Agent reads the /usr/spool/lp/default file specified after the FILE-NAME label and returns the value in the file to the manager.
-
Reference the user IDs, the amount of disk space used by each user, and the users' e-mail address list
You can add MIB objects in table format to SNMP Agent by specifying a specific value in a file as the MIB value. An example is given below.
A list of user IDs, the amount of disk space used by each user, and their e-mail addresses are stored in the /opt/OV/prg_samples/eagent/user_disk_space file. The following is an example of this data:
# User ID User Name Disk Space Email Address 100 zach 120 zach@server1 201 alice 65 alice@server2 320 john 2 john@server3 119 craig 500 root@server1 217 steve 75 steve@server1 83 bob 111 bob@bobby
This table has four columns and six rows. Every table defined using the Extensible SNMP Agent must have a column or a set of columns that uniquely define the row. In some models, this column would be called a key. In this example, the first column is unique. The User ID is unique on this system. If the User Names are unique, the second column could be used as the key.
fUserDiskTable OBJECT-TYPE SYNTAX SEQUENCE OF FuserDiskEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "List of users and the number of kilobytes in their home directory. FILE-NAME: /opt/OV/prg_samples/eagent/ user_disk_space" ::= { fdisk 1 } fUserDiskEntry OBJECT-TYPE SYNTAX FuserDiskEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "This macro documents the column that uniquely describes each row." INDEX { fUID } ::= { fUserDiskTable 1 } FUserDiskEntry ::= SEQUENCE { fUID INTEGER, fUserName DisplayString, fUserDiskSpace INTEGER, fUserEmailAddress DisplayString } fUID OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "User's unique ID" ::= { fUserDiskEntry 1 } fUserName OBJECT-TYPE SYNTAX DisplayString ACCESS read-only STATUS mandatory DESCRIPTION "User login name" ::= { fUserDiskEntry 2 } fUserDiskSpace OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Amount of disk space (in kilobytes) used by the user." ::= { fUserDiskEntry 3 } fUserEmailAddress OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "Email address for the user" ::= { fUserDiskEntry 4 }
The first OBJECT-TYPE macro, fUserDiskTable, describes the file name associated with the object. The second OBJECT-TYPE macro, fUserDiskEntry, describes the column that uniquely identifies a row. The next entry, FUserDiskEntry, is for documentation purposes. This entry lists the columns in the table.
The last four OBJECT-TYPE macros define individual columns.
If the agent receives a GetNextRequest for fUserDiskTable.fUserDiskEntry.fUID, the agent will read the entire file /opt/OV/prg_samples/eagent/user_disk_space. The agent then sorts the table based on the object specified in the INDEX clause. The sorted table will then look like this:
83 bob 111 bob@bobby 100 zach 120 zach@server1 119 craig 500 root@server1 201 alice 65 alice@server2 217 steve 75 steve@server1 320 john 2 john@server3
As a result, SNMP Agent returns the first value in the table. This is the value in the first column of the first row. The manager receives 83 as the MIB value of the object ID flintstones.fdisk.fUserDiskTable.fUserDiskEntry.fUID.83. Next, if SNMP Agent receives a GetNextRequest for the object ID fUserDiskTable.fUserDiskEntry.fUID.83, SNMP Agent checks to see if the file has been updated. If the file has been updated, SNMP Agent reloads the /opt/OV/prg_samples/eagent/user_disk_space file and then returns the User ID in row 2 as the MIB value.
If SNMP Agent receives a GetNextRequest for the object ID flintstones.fdisk.fUserDiskTable.fUserDiskEntry.fUID.320, SNMP Agent returns the first value in column 2 because there is no more User ID row. The object ID is flintstones.fdisk.fUserDiskTable.fUserDiskEntry.fUserName.83 and the MIB value is bob.
If SNMP Agent receives a GetRequest for the object ID flintstones.fdisk.fUserDiskTable.fUserDiskEntry.fUserEmailAddress.217, SNMP Agent searches row 217 of the Email Address column and returns steve@server1 as the MIB value.
To change the e-mail address of alice from alice@server2 to alice@mailer, issue a SetRequest specifying flintstones.fdisk.fUserDiskTable.fUserDiskEntry.fUserEmailAddress.201 as the object ID and alice@mailer as the MIB value. SNMP Agent replaces the value in the table in the /opt/OV/prg_samples/eagent/user_disk_space file with the specified value.
-
List root processes
You can configure SNMP Agent to execute a UNIX command before reading a file. To do so, specify the UNIX command after the FILE-COMMAND label in the DESCRIPTION clause in the /etc/SnmpAgent.d/snmpd.extend file. The example below shows how to specify the FILE-COMMAND line to output a list of root processes.
fUserRootProcessTable OBJECT-TYPE SYNTAX SEQUENCE OF FuserRootProcessEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "List of root processes. Do not execute command more than every 60 seconds. FILE-COMMAND: /opt/OV/prg_samples/eagent FILE-COMMAND-FREQUENCY: 60 FILE-NAME: /opt/OV/prg_samples/eagent /root_processes" ::= { fprocess 1 } fUserRootProcessEntry OBJECT-TYPE SYNTAX FuserRootProcessEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "This macro documents the column that uniquely describes each row." INDEX { fProcessID } ::= { fUserRootProcessTable 1 } FUserRootProcessEntry ::= SEQUENCE { fProcessID INTEGER, fProcessName DisplayString } fProcessID OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "Process ID" ::= { fUserRootProcessEntry 1 } fProcessName OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "Name of process" ::= { fUserRootProcessEntry 2 }
When SNMP Agent receives from a manager the GetRequest shown below, SNMP Agent first executes the /opt/OV/prg_samples/eagent/get_process command specified after the FILE-COMMAND label.
fprocess.fuserRootProcessTable.fUserRootProcessEntry.fProcessID fprocess.fuserRootProcessTable.fUserRootProcessEntry.fProcessName
The /opt/OV/prg_samples/eagent/get_process command creates an /opt/OV/prg_samples/eagent/root_process file that contains the IDs and names of the root processes. Upon the completion of command execution, SNMP Agent reads the /opt/OV/prg_samples/eagent/root_process file, sorts the table, and returns the value in the first column of the first row to the manager.
By default, SNMP Agent does not execute the /opt/OV/prg_samples/eagent/get_process command in response to a GetRequest from a manager if the time that elapsed since SNMP Agent last executed the /opt/OV/prg_samples/eagent/get_process command is 10 seconds or fewer. SNMP Agent returns to the manager the value in the file read during the previous execution. You can change this default interval to any value using the FILE-COMMAND-FREQUENCY label. For example, to make SNMP Agent execute the command hourly, specify the FILE-COMMAND-FREQUENCY line as follows:
FILE-COMMAND-FREQUENCY: 3600
You can configure SNMP Agent to communicate with a UNIX process instead of the UNIX command specified after the FILE-COMMAND label. To do so, write the PIPE-IN-NAME and PIPE-OUT-NAME lines of the DESCRIPTION clause in the /etc/SnmpAgent.d/snmpd.extend file. SNMP Agent writes data into the file specified in the PIPE-OUT-NAME line before reading the file specified in the FILE-NAME line. The UNIX process reads the data, changes the value in the file specified in the FILE-NAME line, and notifies SNMP Agent of the completion using the file specified in the PIPE-IN-NAME line. Like the example for specifying the FILE-COMMAND label, the following example shows how to specify the PIPE-IN-NAME and PIPE-OUT-NAME labels to output a list of root processes. Note that any definitions identical to those in the FILE-COMMAND example are omitted.
fUserRootProcessTable OBJECT-TYPE SYNTAX SEQUENCE OF FuserRootProcessEntry ACCESS not-accessible STATUS mandatory DESCRIPTION "List of root processes. PIPE-IN-NAME: /tmp/fifo_in PIPE-OUT-NAME: /tmp/fifo_out FILE-NAME: /opt/OV/prg_samples/eagent/ root_processes" ::= { fprocess 1 }
When SNMP Agent receives from a manager a GetNextRequest for the object shown below, SNMP Agent first writes data into the /tmp/fifo_out file.
fprocess.fUserRootProcessTable.fUserRootProcessEntry.fProcessID fprocess.fUserRootProcessTable.fUserRootProcessEntry.fProcessName
For details about the data, see the description of the data that is passed to pipe_out_name in 2.10.2(2) Extended MIB objects in table format.
The UNIX process reads this request message and creates an /opt/OV/prg_samples/eagent/root_processes file. The created file contains the IDs and names of the root processes. The UNIX process then writes 0 into the /tmp/fifo_in file and notifies SNMP Agent that it has successfully created the file. SNMP Agent reads the /tmp/fifo_in file and checks whether 0 is set. If 0 is set, the agent reads the /opt/OV/prg_samples/eagent/root_processes file, sorts the table in the file, and returns to the manager the value in the first column of the first row of the table.
By default, SNMP Agent does not write any data into the file specified after the PIPE-OUT-NAME label in response to a GetRequest or GetNextRequest from a manager if the time that elapsed since SNMP Agent last wrote the file is 10 seconds or fewer. SNMP Agent returns to the manager the value in the file it read previously. You can change this default interval to any value using the PIPE-FREQUENCY label.
If SNMP Agent receives a SetRequest from a manager, Agent writes data into the file specified after the PIPE-OUT-NAME label before and after reading the file specified in the FILE-NAME line. The UNIX process receives data from the file specified after the PIPE-OUT-NAME label, performs the specified action, and writes 0 into the file specified after the PIPE-IN-NAME label.
-
Modify the inetd(1M)'s configuration file
If you specify a UNIX command after the FILE-COMMAND label, SNMP Agent acts as follows: Upon receiving a SetRequest from a manager, SNMP Agent executes the specified UNIX command before and after modifying the file specified after the FILE-NAME label. The sample code below uses this feature to modify the inetd(1M) configuration file.
fInetdConf OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS mandatory DESCRIPTION "The configuration file for inetd FILE-COMMAND: /opt/OV/prg_samples/eagent /update_inetd $r FILE-COMMAND-FREQUENCY: 7200 FILE-NAME: /etc/inetd.conf" ::= { fconfig 1 }
Suppose that SNMP Agent receives from a manager a SetRequest for the object with object identifier flintstones.fconfig.fInetdConf.0 and that the MIB value specified in the request is a value in the inetd.conf configuration file. In this case, SNMP Agent performs the following procedure:
-
Execute the /opt/OV/prg_samples/eagent/update_inetd SetRequest command.
-
Modify the Set value in the /etc/inetd.conf file to the Set value specified in the SetRequest.
-
Execute the /opt/OV/prg_samples/eagent/update_inetd PostSetRequest command.
The /opt/OV/prg_samples/eagent/update_inetd command then checks the first argument. If the first argument is a PostSetRequest, the /opt/OV/prg_samples/eagent/update_inetd command executes the /etc/inetd -c command. This causes /etc/inetd to re-read the configuration file.