SNMP PROTOCOL AND THE APPLIED TO MONITOR SERVER’S RESOURCE

18 237 0
SNMP PROTOCOL AND THE APPLIED TO MONITOR SERVER’S RESOURCE

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

VIETNAM NATIONAL UNIVERSITY, HANOI UNIVERSITY OF ENGINEERING AND TECHNOLOGY ---------------------------------------- INTERNSHIP REPORT INFORMATION TECHNOLOGY TITLE: SNMP PROTOCOL AND THE APPLIED TO MONITOR SERVER’S RESOURCE Supervisor: Nguyễn Đức Huy Trần Văn Hoàn Assessment Lecturer: MSc. Vũ Quang Dũng Student: Nguyễn Tuấn Anh Code: 10020011 Group: K55CA Hanoi, September 2013 Team No. 1 2 Fullname Nguyễn Tuấn Anh Vương Khả Phú Code 10020011 10020475 1 Class K55CA K55CB Table of Contents I. Introduction ....................................................................................................................4 1. The company .............................................................................................................4 2. The job .......................................................................................................................4 3. The problem ...............................................................................................................4 II. The problem requirements ............................................................................................5 1. The problem declaration in detail ..............................................................................5 2. Work assignment .......................................................................................................5 III. Summary of the theory, algorithm and solution .........................................................5 1. SNMP.........................................................................................................................5 1.1 Introduction to snmp protocol ..............................................................................5 1.2 The related theories, algorithms and solution ......................................................6 1.3 Framework SNMP4J ............................................................................................7 2. The student’s solution ................................................................................................7 2.1 Overview ..............................................................................................................7 2.2 Getting server’s information ................................................................................7 2.3 Implement Agent and Manager ..........................................................................11 IV. Results and Perspectives ...........................................................................................15 1. Skills and Knowledge ..............................................................................................15 2. The future work to improve the product/solution ....................................................15 2 ACKNOWLEDGMENT I would like to express my deep appreciation to the company Viettel, my supervisors Nguyễn Đức H`uy and Trần Văn Hoàn who has facilitated, guided me during this intership. I would also like to give a big thank to the lecturer Vũ Quang Dũng for comments, suggestions, and assistance as the writing progressed. 3 I. Introduction 1. The company Viettel is one of the world’s fastest growing telecom operators. It has been well known as a pioneer who has ushered in a telecommunications revolution in just a few years, transforming telecom services to a commodity for all social classes and to all rural and remote areas. With year-on-year revenue doubled during 5 consecutive years between 2005 and 2010, Viettel is listed among the world’s fastest growing telecom operators and is placed among the top 15 telecom companies in terms of cellular connections (ranked by GSMA’s Wireless Intelligence). Viettel has currently operations in six markets over Asia, Latin America and Africa, covering a total population of nearly 170 million people. In 2011, Viettel’s revenue reached 6 billion USD with 60 million subscribers worldwide. In these markets, Viettel owns the largest network infrastructure by official launch date. Viettel boasts its first group in the world initiating free Internet connections and services for all public schools which has directly benefited about 27 million teachers, pupils and students in these countries. 2. The job Understanding about SNMP protocol and applying it to real world problems. Time from 12/08/2013 to 30/09/2013 contains three stages: + Understanding about SNMP. + Researching about the way that queries server’s resource information: CPU, RAM, HDD. + Use SNMP protocol in monitoring and manager server’s resource . 3. The problem With any system, the job of manager and monitoring is mandatory. This help our system works well and stable. Any part is overloaded will be notified to the administration to take the appropriate actions. So we are developing a system to do this job on servers. First, we need to get the PC’s resource information. Then base on that, we will send the warning messages if some components work over the threshold. 4 II. The problem requirements 1. The problem declaration in detail + Gathering information about resource useage on the server. + Build a warning system that can send an email to the manager when we has a component (in this case, it maybe CPU or RAM) working overload (above the threshold). + The manager can change the threshold of RAM or CPU use on the system. 2. Work assignment + Vương Khả Phú: understanding three versions of snmp protocol, find a framework supported SNMP, build manager and agent, build Get, Trap function. + Nguyễn Tuấn Anh: understanding three versions of snmp protocol, build file MIB, build manager và agent, build Set, Email function. + The job breaks into three stages:  Stage 1: understanding SNMP and a library snmp4j that supported SNMP.  Stage 2: Find out oid of PC in Linux and windows. Get information from PC.  Stage 3: Build SnmpAgent and SnmpManager. III. Summary of the theory, algorithm and solution 1. SNMP 1.1 Introduction to snmp protocol Simple Network Management Protocol (SNMP) is an "Internet-standard protocol for managing devices on IP networks". Devices that typically support SNMP include routers, switches, servers, workstations, printers, modem racks and more. It is used mostly in network management systems to monitor network-attached devices for conditions that warrant administrative attention. It consists of a set of standards for network management, including an application layer protocol, a database schema, and a set of data objects. SNMP exposes management data in the form of variables on the managed systems, which describe the system configuration. These variables can then be queried (and sometimes set) by managing applications. In typical SNMP uses, one or more administrative computers, called managers, have the task of monitoring or managing a group of hosts or devices on a computer network. Each managed system executes, at all times, a software component called an agent which reports information via SNMP to the manager. Essentially, SNMP agents expose management data on the managed systems as variables. The protocol also permits active management tasks, such as modifying and 5 applying a new configuration through remote modification of these variables. The variables accessible via SNMP are organized in hierarchies. These hierarchies, and other metadata (such as type and description of the variable), are described by Management Information Bases (MIBs). An SNMP-managed network consists of three key components: 1. Managed device 2. Agent — software which runs on managed devices 3. Network management system (NMS) — software which runs on the manager A managed device is a network node that implements an SNMP interface that allows unidirectional (read-only) or bidirectional (read and write) access to nodespecific information. Managed devices exchange node-specific information with the NMSs. Sometimes called network elements, the managed devices can be any type of device, including, but not limited to, routers, access servers, switches, bridges, hubs, IP telephones, IP video cameras, computer hosts, and printers. An agent is a network-management software module that resides on a managed device. An agent has local knowledge of management information and translates that information to or from an SNMP-specific form. A network management system (NMS) executes applications that monitor and control managed devices. NMSs provide the bulk of the processing and memory resources required for network management. One or more NMSs may exist on any managed network. 1.2 The related theories, algorithms and solution Poll method Principle of operation: Manager always asks information from Device. If Manager does not ask then Device does not answer, if Manager asks then Device must answers. By frequently asked, Manager always updates information from Device. Figure 1. Illustration of Poll method 6 Alert method Principle of operation: In Device whenever happened an event then Device automated notifies Manager. Manager does not frequently ask information from Device. Figure 2. Illustration of Alert method 1.3 Framework SNMP4J SNMP4J is an enterprise class free open source and state-of-the-art SNMP implementation for Java™ 2SE 1.4 or later. SNMP4J supports command generation (managers) as well as command responding (agents). 2. The student’s solution 2.1 Overview The work includes two main stages: + Get information of CPU, RAM, HDD in server bases on Agent that was already installed in operating system. Implementing basic Trap method (this purpose is understanding more about SNMP protocol and simple application). + Build an software that monitors two components CPU and RAM of server. When ever the operating parameter of them is over the threshold (this value will be entered from graphical user interface), an email will be sent to the administrator’s mail box. 2.2 Getting server’s information 2.2.1 Starting SNMP Agent In every server or personal computer, the operation system has integrated SNMP Agent. To get information, we just need to start this agent. 7 In Windows: + Go to Control Panel, select Turn Windows features on or off, select check box Simple Network Management Protocol (SNMP) then OK. + We start Services to check whenever SNMP Service is running or not, then double click to this service, switch to tab Sercurity. In groupbox Accepted community names, add another read-community string which is “public”. Then switch to tab Agent select all the Services. In Ubuntu 11.04: + Install snmpd: sudo apt-get install snmpd Computer asked: Do you want to continue [Y/N] Type Y. + Configure: Make new file snmpd.conf like this: move /etc/snmp/snmpd.conf to /etc/snmp/snmpd.conf.org file root@ubuntu:~# mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.org root@ubuntu:~# nano /etc/snmp/snmpd.conf Save the below line to file rocommunity public syslocation "Viettel-IT and UET" syscontact phuvk_55@vnu.edu.vn Make change to /etc/default/snmpd file like this: From: # snmpd options (use syslog, close stdin/out/err). SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1' To: # snmpd options (use syslog, close stdin/out/err). #SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1' SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf' Restart snmpd: /etc/init.d/snmpd restart 8 2.2.2 Implement Manager to get information from Agent First let look at the below model to get the general ideal of how does the software work Server SNMP Agent Response Request Notify SNMP Manager Administrator Change threshold Because SNMP protocol exchange message throw PDU package so first, we implement a general method to send PDU package of GET type to Agent: /** * The oids is the collection of OID we want to get */ public ResponseEvent get(OID oids[]) { PDU pdu = new PDU(); for (OID oid : oids) { pdu.add(new VariableBinding(oid)); } pdu.setType(PDU.GET); return snmp.send(pdu, getTarget()); } As you can see, we has getTarget() method to get the address of Agent. From the returned value ResponseEvent, we can have the value we want. So to get any information of server, we just need the OID of them. For example: OID of sysDescription: .1.3.6.1.2.1.1.1.0 OID of sysName: .1.3.6.1.2.1.1.5.0 OID of CPU: .1.3.6.1.2.1.25.3.3.1.2 From that we can just implement some code to get to know SNMP protocol by getting the information of server, then the output of the tested personal computer is: 9 System Description:Hardware: x86 Family 6 Model 42 Stepping 7 AT/AT COMPATIBLE - Software: Windows Version 6.2 (Build 9200 Multiprocessor Free) System Name: NTA-Lap CPU1 used 5% CPU2 used 14% CPU3 used 7% CPU4 used 4% Total Ram: 1.9375 Ram Used: 1.4375 C:\ Label: Serial Number 54a3f7fe Total: 50.289062 Used: 29.351562 D:\ Label:Data Serial Number 146b5b5d Total: 127.83594 Used: 60.941406 E:\ Label:Entertainment Serial Number eabade41 Total: 267.9922 Used: 217.58203 F:\ Label:U Serial Number 6166ecae Total: 19.527344 Used: 7.5859375 G:\ Total: 0.0 Used: 0.0 Virtual Memory Total: 3.125 Used: 2.25 2.2.3 Demo simple Trap method We will implement both Trap sender and Trap receiver. First to build Trap receiver we need a method to listen on the fix port: public void listen(Address address) { TransportMapping transport = new TransportMapping; // this to handle the message come in createMessageProcessingModels(); //add all security protocols addSecurityProtocols(); //create target Target target = new Target(); target.setCommunity(new OctetString("public")); //start listening transport.listen(); } 10 Then we need to handle PDU that came in (we just deal with it in a simple way) /** * This method will be called whenever a pdu is received on * the given port specified in the listen() method */ public void processPdu(Event event) { PDU pdu = event.getPDU(); if (pdu != null) { pdu.getType()); pdu.getVariableBindings()); } } With Trap sender, just like Manager we built before, we need to send a PDU of Trap type to the specific address: /** * This methods sends the V1 trap to the local host in port * 162 */ public void sendTrap() { PDU pdu = new PDU(); pdu.setType(PDU.TRAP); pdu.setEnterprise(new OID(oid)); pdu.setGenericTrap(PDU.COLDSTART); pdu.setAgentAddress(new IpAddress(ipAddress)); snmp.send(pdu, getTarget()); } The Output of program (informed Trap receiver was listening on localhost address at 162 port, whenever received a trap then notify the type and variables inside that trap) Listening on: 127.0.0.1/162 Received PDU ... Trap type = -92 Variables = [] 2.3 Implement Agent and Manager 2.3.1 Implement Agent With an Agent, we need to have three main parts: all object that agent managed, community string, the read – write access to every object. To manage an object, we will build the below method. 11 /** * Clients can register the MO they need */ public void registerManagedObject(ManagedObject mo) { server.register(mo); } ManagedObject is a managed object type we build that can set the read-write access. We can add the community string from: protected void addCommunities(SnmpCommunity c) { Agent agent = getAgent(); Community newRow = c.createNewRowCommunityInAgent(); agent.setCommunity(newRow, “public”, active); } Add read-write throw view (an property of SNMP protocol) protected void addViews(MIB m) { m.addSecurity(); m.addAccess(“fullReadView”); m.addAccess(“fullWriteView”); } 2.3.2 Implement Agent that monitors server’s resource With this requirement, we need to build an Agent which has ability to get the system’s parameter, also this Agent must manages the threshold value that can change through SET method of SNMP protocol. First, we need to initiate an Agent then having two managed objects for that Agent to manage (two objects are the threshold of CPU and RAM): public void init() throws IOException { agent = new SNMPAgent(address); agent.start(); cpuMO = MOCreator.createReadWrite(cpuMaxOID, cpuMaxValue); ramMO = MOCreator.createReadWrite(ramMaxOID, ramMaxValue); agent.registerManagedObject(cpuMO); agent.registerManagedObject(ramMO); } To monitor the server, Agent need an Thread to frequently ask parameters of CPU, RAM then compare to the threshold value and notify to the administrator if one of them is overloaded: 12 public void run() { while (true) { try { Thread.sleep(10000); //10s float usedCpu = getCPUValue(); if (usedCpu > cpuMax) { notifyAdmin(); } float usedRam = getRamValue(); if (usedRam > ramMax) { notifyAdmin(); } } 2.3.3 Implement Manager We will build Manager with ability to change the threshold value in Agent through Set method of SNMP protocol. Like GET protocol, we also use PDU package but type is SET (in SET type, we have the value of variable in PDU package, this is so obvious): public void setValue(OID oid, Object value) { Variable var; PDU pdu = new PDU(); pdu.add(new VariableBinding(oid, var)); pdu.setType(PDU.SET); snmp.set(pdu, getTarget()); } So in here, we had completely implemented the software, let look at some images: Figure 3. Message to the screen when Agent run 13 Figure 4. Change threshold from Manager and see what Agent informed Figure 5. Agent notify through email (RAM in this case) Figure 6. Agent notify through email (CPU in this case) 14 IV. Results and Perspectives 1. Skills and Knowledge  Having an overview as well as the solution of monitoring server’s resource problem.  Understanding more about SNMP protocol and SNMP4J framework.  Improve teamwork skills, presentation skills, report writing.  Improve division of labor skill, time management skill.  Be familiar with professional working environment. 2. The future work to improve the product/solution  Monitoring in many servers. References https://sites.google.com/site/snmptoantap/home http://www.snmp4j.org/ http://www.jayway.com/2010/05/21/introduction-to-snmp4j/ 15 Comments: ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… Hanoi, September 2013 Supervisor (Signature, Full name & company seal) 16 Comments: ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………… ……………………………………….………………………………………………… ……………….………………………………………………………………….……… ………………… Mark: ……. In words: ………… Hanoi, 2013 Assessment Lecturer (Signature & Full name) 17 [...]... of SNMP protocol) protected void addViews(MIB m) { m.addSecurity(); m.addAccess(“fullReadView”); m.addAccess(“fullWriteView”); } 2.3.2 Implement Agent that monitors server’s resource With this requirement, we need to build an Agent which has ability to get the system’s parameter, also this Agent must manages the threshold value that can change through SET method of SNMP protocol First, we need to initiate... problem  Understanding more about SNMP protocol and SNMP4 J framework  Improve teamwork skills, presentation skills, report writing  Improve division of labor skill, time management skill  Be familiar with professional working environment 2 The future work to improve the product/solution  Monitoring in many servers References https://sites.google.com/site/snmptoantap/home http://www .snmp4 j.org/ http://www.jayway.com/2010/05/21/introduction -to -snmp4 j/... Agent then having two managed objects for that Agent to manage (two objects are the threshold of CPU and RAM): public void init() throws IOException { agent = new SNMPAgent(address); agent.start(); cpuMO = MOCreator.createReadWrite(cpuMaxOID, cpuMaxValue); ramMO = MOCreator.createReadWrite(ramMaxOID, ramMaxValue); agent.registerManagedObject(cpuMO); agent.registerManagedObject(ramMO); } To monitor the. .. implemented the software, let look at some images: Figure 3 Message to the screen when Agent run 13 Figure 4 Change threshold from Manager and see what Agent informed Figure 5 Agent notify through email (RAM in this case) Figure 6 Agent notify through email (CPU in this case) 14 IV Results and Perspectives 1 Skills and Knowledge  Having an overview as well as the solution of monitoring server’s resource. .. simple Trap method We will implement both Trap sender and Trap receiver First to build Trap receiver we need a method to listen on the fix port: public void listen(Address address) { TransportMapping transport = new TransportMapping; // this to handle the message come in createMessageProcessingModels(); //add all security protocols addSecurityProtocols(); //create target Target target = new Target();... then notify the type and variables inside that trap) Listening on: 127.0.0.1/162 Received PDU Trap type = -92 Variables = [] 2.3 Implement Agent and Manager 2.3.1 Implement Agent With an Agent, we need to have three main parts: all object that agent managed, community string, the read – write access to every object To manage an object, we will build the below method 11 /** * Clients can register the. .. MOCreator.createReadWrite(ramMaxOID, ramMaxValue); agent.registerManagedObject(cpuMO); agent.registerManagedObject(ramMO); } To monitor the server, Agent need an Thread to frequently ask parameters of CPU, RAM then compare to the threshold value and notify to the administrator if one of them is overloaded: 12 public void run() { while (true) { try { Thread.sleep(10000); //10s float usedCpu = getCPUValue(); if (usedCpu > cpuMax)... Manager with ability to change the threshold value in Agent through Set method of SNMP protocol Like GET protocol, we also use PDU package but type is SET (in SET type, we have the value of variable in PDU package, this is so obvious): public void setValue(OID oid, Object value) { Variable var; PDU pdu = new PDU(); pdu.add(new VariableBinding(oid, var)); pdu.setType(PDU.SET); snmp. set(pdu, getTarget());... built before, we need to send a PDU of Trap type to the specific address: /** * This methods sends the V1 trap to the local host in port * 162 */ public void sendTrap() { PDU pdu = new PDU(); pdu.setType(PDU.TRAP); pdu.setEnterprise(new OID(oid)); pdu.setGenericTrap(PDU.COLDSTART); pdu.setAgentAddress(new IpAddress(ipAddress)); snmp. send(pdu, getTarget()); } The Output of program (informed Trap receiver... used 7% CPU4 used 4% Total Ram: 1.9375 Ram Used: 1.4375 C:\ Label: Serial Number 54a3f7fe Total: 50.289062 Used: 29.351562 D:\ Label:Data Serial Number 146b5b5d Total: 127.83594 Used: 60.941406 E:\ Label:Entertainment Serial Number eabade41 Total: 267.9922 Used: 217.58203 F:\ Label:U Serial Number 6166ecae Total: 19.527344 Used: 7.5859375 G:\ Total: 0.0 Used: 0.0 Virtual Memory Total: 3.125 Used: 2.25 ... queries server’s resource information: CPU, RAM, HDD + Use SNMP protocol in monitoring and manager server’s resource The problem With any system, the job of manager and monitoring is mandatory... move /etc /snmp/ snmpd.conf to /etc /snmp/ snmpd.conf.org file root@ubuntu:~# mv /etc /snmp/ snmpd.conf /etc /snmp/ snmpd.conf.org root@ubuntu:~# nano /etc /snmp/ snmpd.conf Save the below line to file rocommunity... Summary of the theory, algorithm and solution SNMP .5 1.1 Introduction to snmp protocol 1.2 The related theories, algorithms and solution 1.3 Framework SNMP4 J

Ngày đăng: 08/10/2015, 13:54

Tài liệu cùng người dùng

Tài liệu liên quan