SNMP structured query method, system and medium
By dividing it into ordinary query and subquery in SNMP query, loop querying the index of the specified column, solving the efficiency problem when obtaining multiple matches in the existing technology, and implementing an efficient and readable query method, which is suitable for different scenarios SNMP query requirements.
Patent Information
- Application Number
- CN202010905167.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-01
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2040-09-01
AI Technical Summary
During the SNMP query process, it is difficult for the existing technology to efficiently obtain multiple matches, while avoiding the existence of useless data. It requires trade-offs in different scenarios, so it cannot meet the needs of quickly finding the first match or obtaining multiple matches at once.
Provide a SNMP structured query method. By dividing query conditions into ordinary queries and subqueries, using SNMP's GETNEXT request to loop through the last index of the specified column, obtain the index set that meets the matching conditions, and obtain the complete OID through the GET request. Value, supports multiple matching methods and nested queries.
It improves the efficiency of Table-type data query, enhances the readability and scalability of the query, can quickly obtain specific values of MIB nodes, reduces redundant code structure, and is suitable for microservice architecture.
Smart Images

Figure CN112069221B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network management protocols, and in particular, to an SNMP structured query method, system and medium. In particular, the present invention relates to a syntax format and a usage interface applied to SNMP Table type queries. The user provides the SNMP access information of the peer IP and the query conditions (the type of which is a yml file in a standard format) written based on the syntax specification to the server. After receiving the query request, the server generates a corresponding SNMP request according to the provided information, parses and processes the query content within the program, and finally returns the result (set) of the request. Background Art
[0002] SNMP (Simple Network Management Protocol) is an indispensable part of today's network management software and is also inseparable from daily operation and maintenance work. It sends different types of SNMP requests to the target device to obtain different types of information, thereby achieving the purpose of management.
[0003] In the process of using SNMP, the commonly used methods are single-point query (GET, GETNEXT) and full acquisition (GETBUILK). The implementation principle of the latter GETBULK is to loop GETNEXT through SNMP internally until the last root leaf node of the current MIB. The difference between the two is obvious, and users can choose according to different scenarios. However, some scenarios must make trade-offs. If you want to find the first match as quickly as possible, choosing GETNEXT is undoubtedly the first choice, but in this case, you have to give up the advantage of GETBULK that you only need to send one SNMP request; but if you want to get multiple matches at one time, using GETBULK is undoubtedly necessary, but you will inevitably have to accept the existence of redundant and useless data.
[0004] Therefore, driven by this demand, it was decided to generate a standard query specification. Users only need to specify the number and type of returned data, write query conditions according to established rules, support multiple matching methods, and can use nested queries to respond to the correct results. Summary of the invention
[0005] In view of the defects in the prior art, the object of the present invention is to provide an SNMP structured query method, system and medium.
[0006] A SNMP structured query method provided by the present invention includes:
[0007] Step S1: Find the index set that meets the query conditions;
[0008] Step S2: Get the value of the matched index in the specific column.
[0009] Preferably, the step S1:
[0010] According to the complexity of the query requirements, the query conditions are divided into two categories:
[0011] Normal query: Applicable to simple matching. When the value of the specified column can be determined, that is, when the value field in the where query body is clearly known, use normal query;
[0012] Through the native GETNEXT request provided by SNMP, the last index of the specified column configured in the input parameter column_oid is cyclically queried, and all index records that meet the matching conditions are intersected with other query results;
[0013] The specified column refers to the column represented by the filled column_oid in an snmp oid table;
[0014] Subquery: Applicable to complex queries. When the value of a specified column needs to be obtained indirectly by querying other columns, that is, when the value field is unknown and needs to be obtained through query, use the subquery method;
[0015] Ordinary queries and subqueries cannot be used in the same query body at the same time, that is, a where query cannot have both a value field and a sub_query;
[0016] Subqueries are used when the values of the columns to be compared are not directly known but can be obtained indirectly through the same query logic. Subqueries return matching index records and intersect them with other query results.
[0017] Preferably, the step S2:
[0018] According to the type type in the query body select, one represents the first matching item, and list represents searching for all matching items. The items are combined with the found indexes that meet the query conditions and concatenated into a complete OID.
[0019] Use the SNMP GET request to obtain the value corresponding to the complete OID after splicing.
[0020] An SNMP structured query system provided by the present invention comprises:
[0021] Module S1: Find the index set that meets the query conditions;
[0022] Module S2: Get the value of the matched index in a specific column.
[0023] Preferably, the module S1:
[0024] According to the complexity of the query requirements, the query conditions are divided into two categories:
[0025] Normal query: Applicable to simple matching. When the value of the specified column can be determined, that is, when the value field in the where query body is clearly known, use normal query;
[0026] Through the native GETNEXT request provided by SNMP, the last index of the specified column configured in the input parameter column_oid is cyclically queried, and all index records that meet the matching conditions are intersected with other query results;
[0027] The specified column refers to the column represented by the filled column_oid in an snmp oid table;
[0028] Subquery: Applicable to complex queries. When the value of a specified column needs to be obtained indirectly by querying other columns, that is, when the value field is unknown and needs to be obtained through query, use the subquery method;
[0029] Ordinary queries and subqueries cannot be used in the same query body at the same time, that is, a where query cannot have both a value field and a sub_query;
[0030] Subqueries are used when the values of the columns to be compared are not directly known but can be obtained indirectly through the same query logic. Subqueries return matching index records and intersect them with other query results.
[0031] Preferably, the module S2:
[0032] According to the type type in the query body select, one represents the first matching item, and list represents searching for all matching items. The items are combined with the found indexes that meet the query conditions and concatenated into a complete OID.
[0033] Use the SNMP GET request to obtain the value corresponding to the complete OID after splicing.
[0034] A computer-readable storage medium storing a computer program according to the present invention is characterized in that when the computer program is executed by a processor, the steps of any one of the above-mentioned SNMP structured query methods are implemented.
[0035] Compared with the prior art, the present invention has the following beneficial effects:
[0036] The advanced query of the present invention undoubtedly improves the efficiency of Table type data query, which is not only more readable, but also has certain scalability. When obtaining certain specific values among the many values of MIB nodes, when it is impossible to obtain them directly, or when there are no obvious distinguishing conditions when obtaining them directly, or when multiple values are obtained in batches and the judgment conditions are consistent, it is faster to use this method. If it is used as a separate SNMP service, it can save the repeated and redundant code structure in different situations, which is also in line with the architecture of today's microservices. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0038] Figure 1 A schematic diagram of an example query structure provided by the present invention.
[0039] Figure 2 A schematic diagram of a program flow provided by the present invention.
[0040] Figure 3 This is a schematic diagram of a Table provided by the present invention. DETAILED DESCRIPTION
[0041] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0042] A SNMP structured query method provided by the present invention includes:
[0043] Step S1: Find the index set that meets the query conditions;
[0044] Step S2: Get the value of the matched index in the specific column.
[0045] Preferably, the step S1:
[0046] According to the complexity of the query requirements, the query conditions are divided into two categories:
[0047] Normal query: Applicable to simple matching. When the value of the specified column can be determined, that is, when the value field in the where query body is clearly known, use normal query;
[0048] Through the native GETNEXT request provided by SNMP, the last index of the specified column configured in the input parameter column_oid is cyclically queried, and all index records that meet the matching conditions are intersected with other query results;
[0049] The specified column refers to the column represented by the filled column_oid in an snmp oid table;
[0050] Subquery: Applicable to complex queries. When the value of a specified column needs to be obtained indirectly by querying other columns, that is, when the value field is unknown and needs to be obtained through query, use the subquery method;
[0051] Ordinary queries and subqueries cannot be used in the same query body at the same time, that is, a where query cannot have both a value field and a sub_query;
[0052] Subqueries are used when the values of the columns to be compared are not directly known but can be obtained indirectly through the same query logic. Subqueries return matching index records and intersect them with other query results.
[0053] Preferably, the step S2:
[0054] According to the type type in the query body select, one represents the first matching item, and list represents searching for all matching items. The items are combined with the found indexes that meet the query conditions and concatenated into a complete OID.
[0055] Use the SNMP GET request to obtain the value corresponding to the complete OID after splicing.
[0056] The SNMP structured query system provided by the present invention can be implemented by the steps and procedures of the SNMP structured query method provided by the present invention. Those skilled in the art can understand the SNMP structured query method as a preferred example of the SNMP structured query system.
[0057] An SNMP structured query system provided by the present invention comprises:
[0058] Module S1: Find the index set that meets the query conditions;
[0059] Module S2: Get the value of the matched index in a specific column.
[0060] Preferably, the module S1:
[0061] According to the complexity of the query requirements, the query conditions are divided into two categories:
[0062] Normal query: Applicable to simple matching. When the value of the specified column can be determined, that is, when the value field in the where query body is clearly known, use normal query;
[0063] Through the native GETNEXT request provided by SNMP, the last index of the specified column configured in the input parameter column_oid is cyclically queried, and all index records that meet the matching conditions are intersected with other query results;
[0064] The specified column refers to the column represented by the filled column_oid in an snmp oid table;
[0065] Subquery: Applicable to complex queries. When the value of a specified column needs to be obtained indirectly by querying other columns, that is, when the value field is unknown and needs to be obtained through query, use the subquery method;
[0066] Ordinary queries and subqueries cannot be used in the same query body at the same time, that is, a where query cannot have both a value field and a sub_query;
[0067] Subqueries are used when the values of the columns to be compared are not directly known but can be obtained indirectly through the same query logic. Subqueries return matching index records and intersect them with other query results.
[0068] Preferably, the module S2:
[0069] According to the type type in the query body select, one represents the first matching item, and list represents searching for all matching items. The items are combined with the found indexes that meet the query conditions and concatenated into a complete OID.
[0070] Use the SNMP GET request to obtain the value corresponding to the complete OID after splicing.
[0071] A computer-readable storage medium storing a computer program according to the present invention is characterized in that when the computer program is executed by a processor, the steps of any one of the above-mentioned SNMP structured query methods are implemented.
[0072] The present invention will be described in more detail below through preferred examples.
[0073] Preferred Example 1:
[0074] Based on the basic SNMP request protocol, query the OID of the Table type through conditions and return the information of the specified column. The specific implementation needs to meet the following requirements:
[0075] 1. You can specify the type of result set to be returned – first match or all matches
[0076] 2. You can specify the columns included in the returned result set
[0077] 3. The query condition supports multiple matching methods, equal, not equal, empty, regular
[0078] 4.Support multi-condition query, and the query conditions are in an "and" relationship
[0079] 5. Support subqueries
[0080] The structure of the MIB tree is clear. The MIB nodes at each level often belong to the same type of value, and the distribution of their child nodes is also equal, that is, the specific leaf index is spliced after the upper-level MIB node. For example, the following two OIDs, 1.3.6.1.2.1.47.1.1.1.1.10 and 1.3.6.1.2.1.47.1.1.1.1.11, belong to the node with OID 1.3.6.1.2.1.47.1.1.1.1, and the suffixes .10 and .11 are leaf indexes, and the index divisions of the lower-level child nodes are often the same. Therefore, for OID: 1.3.6.1.2.1.47.1.1.1.1, it can be understood as a table, the rows represent the index values corresponding to each grandchild node, and the columns represent the divisions of the child nodes. The example is shown in Figure 3.
[0081] Specific requirements are based on this type of OID:
[0082] 1. Specify the columns to be retrieved (returned) in the Table, such as 1.3.6.1.2.1.47.1.1.1.10.
[0083] 2. Configure the query conditions, such as the value of the 1.3.6.1.2.1.47.1.1.1.11 column is 1, and the value of the 1.3.6.1.2.1.47.1.1.1.7 column is not equal to 3.
[0084] 3. Concatenate the index values that meet the conditions and the returned columns to obtain the specific values.
[0085] 4. Return the result.
[0086] Figure 1 This is the query format defined so far. The query syntax itself follows the yml standard format (please refer to the relevant documents for the format of the yml language, which will not be repeated here).
[0087] From the above requirements, we can know that the core of this query is how to obtain the index value that matches the query condition. After obtaining the candidate index set, we only need to query its group and value. Therefore, the algorithm idea is divided into two parts:
[0088] 1. Get the value of the matched index in the specific column -> result concatenation (and subquery)
[0089] 2. Find the index collection that meets the query conditions->Conditional query
[0090] The implementation of the first part is very simple. You only need to determine the type of the return value (first match / no match at all), filter the qualified indexes, and concatenate them into a complete OID. Finally, send a GET request to obtain the return value.
[0091] The second part is the core part. There are two types of query conditions.
[0092] 1. General query
[0093] Through the GETNEXT request, the last index of the specified column is queried, and the intersection of all matching index records and other query results is obtained.
[0094] 2. Subquery
[0095] Subqueries are mainly used when the value of the column to be compared is not directly known but can be obtained indirectly through the same query logic. For example, if you want to compare the value of 1.3.6.1.2.1.47.1.1.1.11 to the value of 1.3.6.1.2.1.47.1.1.1.11 when the value of the 1.3.6.1.2.1.47.1.1.1.10 column is 5, the matched index records are also returned and intersected with other query results.
[0096] Figure 1 This is the query format defined so far. The query syntax itself follows the yml standard format (please refer to the relevant documents for the format of the yml language, which will not be repeated here).
[0097] From the above requirements, we can know that the core of this query is how to obtain the index value that matches the query condition. After obtaining the candidate index set, we only need to query its group and value. Therefore, the algorithm idea is divided into the following two parts. The implementation process is shown in Figure 2 :
[0098] Get the value of the matched index in the specific column -> result splicing (and subquery) (result splicing subquery means splicing the index set returned by the second part with the oid filled in the first part. For example, if the first part is 1.3.4 and the second part returns 5, the splicing result is 1.3.4.5; the subquery means initiating an snmpget request to obtain the spliced oid)
[0099]
[0100] Find the index collection that meets the query conditions->Conditional query
[0101]
[0102] The implementation of the first part is very simple. You only need to combine the index that meets the conditions in the second part according to the type type in the query body select (one represents the first matching item / list represents searching for all matching items) (if no item in the query target matches the query condition in the second part, no result will be returned, which is synonymous with 0 matches), and concatenate (mib is a tree structure, each level has a corresponding identifier (number, or a set of numbers), such as 1.3, 1.3.6 are the second and third levels respectively, oid is actually an expression of the level, which is the concatenation of the identifiers of different levels, and this is what the "concatenation" in the text means) into a complete OID. Finally, use the SNMP GET request to obtain the value corresponding to the complete OID after concatenation.
[0103] The second part is the core part. Here, the query conditions are divided into two categories according to the complexity of the query requirements:
[0104] Normal query: Applicable to simple matching. When the value of the specified column can be determined, that is, when the value field in the where query body is clearly known, use normal query.
[0105]
[0106] Through the native GETNEXT request provided by SNMP, the last index of the specified column configured in column_oid (see column_oid in the configuration template above) (referring to the column represented by the filled column_oid in a snmp oid table) is cyclically queried, and all index records that meet the matching conditions are intersected with other query results. The query conditions of the second part of the other query results, according to the given yml sample, can be concluded to be of list type, that is, multiple query conditions are accepted, so this 'other query' refers to other query conditions in parallel with it
[0107] Subquery: Applicable to complex queries. When the value of a specified column needs to be obtained indirectly by querying other columns, that is, when the value field is unknown and needs to be obtained through query, use the subquery method.
[0108] Ordinary queries and subqueries cannot be used in the same query body at the same time, that is, a where query cannot have both a value field and a sub_query.
[0109] Subqueries are mainly used when the value of the column to be compared is not directly known but can be obtained indirectly through the same query logic. For example, if you want to compare the value of 1.3.6.1.2.1.47.1.1.1.11 to the value of 1.3.6.1.2.1.47.1.1.1.11 when the value of the 1.3.6.1.2.1.47.1.1.1.10 column is 5, the matched index records are also returned and intersected with other query results.
[0110]
[0111] In the description of the present application, it should be understood that the terms "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.
[0112] Those skilled in the art know that, in addition to implementing the system, device and its various modules provided by the present invention in a purely computer-readable program code, it is entirely possible to implement the same program in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded microcontrollers by logically programming the method steps. Therefore, the system, device and its various modules provided by the present invention can be considered as a hardware component, and the modules included therein for implementing various programs can also be considered as structures within the hardware component; the modules for implementing various functions can also be considered as both software programs for implementing the method and structures within the hardware component.
[0113] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A SNMP structured query method, characterized in that: include: Step S1: Find the index set that meets the query conditions; Step S2: Get the value of the matched index in the specific column; Described step S1: According to the complexity of the query requirements, the query conditions are divided into two categories: Normal query: Applicable to simple matching. When the value of the specified column can be determined, that is, when the value field in the where query body is clearly known, use normal query; Through the native GETNEXT request provided by SNMP, the last index of the specified column configured in the input parameter column_oid is cyclically queried, and all index records that meet the matching conditions are intersected with other query results; The specified column refers to the column represented by the filled column_oid in an snmp oid table; Subquery: Applicable to complex queries. When the value of a specified column needs to be obtained indirectly by querying other columns, that is, when the value field is unknown and needs to be obtained through query, use the subquery method; Ordinary queries and subqueries cannot be used in the same query body at the same time, that is, a where query cannot have both a value field and a sub_query; Subqueries are used when the values of the columns to be compared are not directly known but can be obtained indirectly through the same query logic. Subqueries return matching index records and intersect with other query results. Described step S2: According to the type type in the query body select, one represents the first matching item, and list represents searching for all matching items. The items are combined with the found indexes that meet the query conditions and concatenated into a complete OID. Use the SNMP GET request to obtain the value corresponding to the complete OID after splicing.
2. An SNMP structured query system, characterized in that: include: Module S1: Find the index set that meets the query conditions; Module S2: Get the value of the matched index in the specific column; The module S1: According to the complexity of the query requirements, the query conditions are divided into two categories: Normal query: Applicable to simple matching. When the value of the specified column can be determined, that is, when the value field in the where query body is clearly known, use normal query; Through the native GETNEXT request provided by SNMP, the last index of the specified column configured in the input parameter column_oid is cyclically queried, and all index records that meet the matching conditions are intersected with other query results; The specified column refers to the column represented by the filled column_oid in an snmp oid table; Subquery: Applicable to complex queries. When the value of a specified column needs to be obtained indirectly by querying other columns, that is, when the value field is unknown and needs to be obtained through query, use the subquery method; Ordinary queries and subqueries cannot be used in the same query body at the same time, that is, a where query cannot have both a value field and a sub_query; Subqueries are used when the values of the columns to be compared are not directly known but can be obtained indirectly through the same query logic. Subqueries return matching index records and intersect with other query results. The module S2: According to the type type in the query body select, one represents the first matching item, and list represents searching for all matching items. The items are combined with the found indexes that meet the query conditions and concatenated into a complete OID. Use the SNMP GET request to obtain the value corresponding to the complete OID after splicing.
3. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the SNMP structured query method according to claim 1 are implemented.
Citation Information
Patent Citations
Data analysis processing method and system based on SNMP protocol
CN108270599A
Simple network management protocol agent inquiring method and system and MIB tree traversal method
CN108616385A
Data query method and device, server and storage medium
CN110019380A
Variable SNMP data collection with embedded queries
US20180006873A1
