1 /*-
2 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
3 * SNMP Java Client
4 * ჻჻჻჻჻჻
5 * Copyright 2023 MetricsHub
6 * ჻჻჻჻჻჻
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Lesser Public License for more details.
16 *
17 * You should have received a copy of the GNU General Lesser Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
21 */
22
23 package org.metricshub.snmp.client;
24
25 import java.util.List;
26
27 /**
28 * Unified abstraction that both {@link SnmpClient} (live network) and
29 * {@link OfflineSnmpClient} (file‑backed) can implement.
30 */
31 public interface ISnmpClient {
32
33 /**
34 * Performs SNMP get action for a single OID.
35 * @param oid A given OID.
36 * @return The corresponding object as a string.
37 * @throws Exception on error (e.g. no such OID).
38 */
39 String get(String oid) throws Exception;
40
41 /**
42 * Performs SNMP getNext action for a single OID.
43 * @param oid A given OID.
44 * @return The corresponding object as a string.
45 * @throws Exception on error (e.g. no such OID).
46 */
47 String getNext(String oid) throws Exception;
48
49
50 /**
51 * Reads an SNMP table.
52 *
53 * @param rootOID Root OID of the table (e.g. …7.1)
54 * @param selectColumns Numeric column indexes or "ID" for the row index
55 * @return Rows serialized with semicolons (one row per line)
56 */
57 List<List<String>> table(String rootOID, String[] selectColumns) throws Exception;
58
59 /**
60 * Strips the leading dot from an OID string if it exists.
61 *
62 * @param s the OID string to process.
63 * @return the OID string without a leading dot.
64 */
65 default String stripDot(String s) {
66 return s.startsWith(".") ? s.substring(1) : s;
67 }
68
69 /**
70 * Performs SNMP walk action starting from a given OID.
71 * @param oid A given OID.
72 * @return The corresponding object as a string.
73 * @throws Exception on error (e.g. no such OID).
74 */
75 String walk(String oid) throws Exception;
76
77 /**
78 * Frees any resources held by the client, such as network connections or file handles or memory space.
79 */
80 void freeResources();
81 }