My Stuff
Main Page

Other Stuff

Configuring phpSNMP

  • The new customer must first be added to the configuration file used be snmpmon so that snmpmon will begin monitoring that port, thus adding the customer to the MySQL database. This must be done as the superuser. First, the program "snmpmon" must be run from the command line. You must treat this process as though you are adding a new router to be monitored (even if the router is already being monitored, you must do this so that it will reconfigure which ports are being monitored). First look if the router is already being monitored, this is done by issuing the command "snmpmon --list". If the router is in this list, you must temporarily remove it by using the command "snmpmon --delete" followed by the name of the router and hit enter. If the router is not being monitored already, simply make up a name for this router (such as "cisco7200"). Then you must add this router to the configuration by giving the command "snmpmon --add" followed by the name of the router (if the router was being monitored before, use the same name as before). Next you will be prompted for a description of the router, simply give it a name or whatever is deemed necessary. Next you must enter the ip or hostname of the router, it is advisable to enter the ip rather than the hostname so that if the DNS is down, monitoring will not be halted. Next you will be asked for the community that the router is in, the default is usually "public", if this does not work, ask the network administrator. Next you must enter the SNMP port for the router, this number is almost always "161", again ask the network administrator if this does not work. Finally you will be given a list of ports that may look like the following:
    Nr  Description      AdminStatus  OperStatus    InOctets   OutOctets
     1  Serial1/0        Up           Up          3194142755  3997852621
     2  FastEthernet2/0  Up           Up          2743855047  1446276824
     3  Serial4/0        Up           Up          2196954794  3434699181
     4  Serial4/1        Up           Up           162860525   805102164
     5  Serial4/2        Up           Up           358986278   285752214
     6  Serial4/3        Up           Up           358180870  1143394467
     7                   Down         Down
     8                   Down         Down
     9                   Down         Down
    10                   Down         Down
    11  Serial3/0:0      Up           Up           113314095   345064082
    12  Serial3/1:0      Up           Up          1004633431  1734237294
    13  Serial3/2:0      Up           Up            30545092   135339566
    14  Serial3/3:0      Up           Up            74231836   214242839
    15  Loopback0        Up           Up                   0           0
    First you must enter all the ports that you want to be monitored for status changes (if the port goes inactive), for instance: 1,4,5,13. Next you must enter the port numbers to be monitored for utilization, here you must follow the same format as with the previous question. IMPORTANT: If this router was being monitored before, make sure to remember to add all of the ports that were being monitored previously, otherwise they will not be monitored anymore (if you forget which ones were being monitored, ask the network administrator or consult a backup of the configuration file).
    That's all that is needed for changing the configuration for snmpmon. The finaly thing that must be done to snmpmon is to have the superuser stop it ("snmpmon --stop") and then start it again ("snmpmon --start").

  • Next, you must reconfigure the actual phpSNMP scripts to use this new customer. This is done by first going to the directory where phpSNMP is installed and then editing the "" file so that phpSNMP will start using this port. Right now, the file will look something like the following:
    if (eregi("a",$cust))
            $router = "cisco7206";
            $port = "13";
            $login = 1;
            $custname = "Customer A";
    This file only shows one customer entered in phpSNMP. The first important part of this file is the first line:
    if (eregi("a",$cust))
    The "a" in this line is a unique variable that must be assigned to each customer. This variable may be anything, not just a single letter, though it is recommended to use a pattern so that it will be easy to identify which variables are being used and which are available. I suggest using letters of the alphabet, and once you reach "z" start using double letters (e.g. "aa"). This value must correspond to the value in "", but we will come to that later.
    The next line that must be modified is the "$router=" line. This value must correspond to the name of the router that the customer is plugged into. This name must match the value of the HOSTS field in the MySQL database (it will also match the name of the router in the snmpmon configuration), to look up this value, either look at the MySQL database, or use snmpmon by typing "snmpmon --list". Next, you must enter the port that the customer is plugged into. This is the port that snmpmon is monitoring, this value can be attained from the snmpmon configuration file, or from the MySQL database (the INTERFACE column). Next, add a line that just has "$login=1;", this is just a login token (I chose to use this instead of cookies). Finally, add a line for the customer's name. This name will appear in pull-down menus and at the top of their stats page, it should be like the following: "$custname="Customer A";". This is all that must be done to the "" file, just make sure that the brackets are closed of properly.

  • Next, you must modify the "" file. This file is used for authentication purposes. If you are using htpasswd authentication for all customers, the file should look basically like the following:
    if (eregi("customer1",$REMOTE_USER))
            print "<option value=a>Customer A";
    The first part that must be edited in this file is the line:
    if (eregi("customer1",$REMOTE_USER))
    The "customer1" part should be replaced with the login name for the customer (the username that htpasswd will use). Next, add what you would like to appear for this customer's name in the pull-down menu. Next, in the "<option value=a>" part, the value (in this case "a") matches whatever value you gave this customer in, if it does not, this script will not function at all.
    Next, it is advisable to have a "root" section for this file so that whoever logs in as root has access to all the customers' stats. This part will look like the following:
    if (eregi("root",$REMOTE_USER))
            print "<option value=a>Customer A";
            print "<option value=b>Customer B";
            print "<option value=c>Customer C";
            print "<option value=d>Customer D";
    The first part here has the username set to "root" (before we had it as "customer1"). Below that we have a line for each customer that is in the database. This line is just a duplicate of the print line that you entered before for the customer's profile. You must make sure that there is a "<select>" at the beginning and a "</select>" at the end of this file.
    If you are not planning on using htpasswd authentication, you can ignore those instructions and simply have the following in this file:
    <option value=a>Customer A
    Where "Customer A" again is the name to appear in the pull-down menus, and "a" is the variable for this customer, as set up in "". If you are using this method, rather than the htpasswd method, keep in mind that anyone can see any customer's monthly stats.