// example1 — SNMP GET // Usage: ./example1 [host] [community] module example1; import snmp; import std.stdio : writefln, stderr; void main(string[] args) { init_snmp("example1"); string host = args.length > 1 ? args[1] : "udp:localhost:161"; string community = args.length > 2 ? args[2] : "public"; auto sess = SNMPSession.open(host, community, SNMPVersion.v2c); if (!sess.isOpen) { snmp_perror("snmp_open"); return; } auto sysDescr = OID.fromString("1.3.6.1.2.1.1.1.0"); if (!sysDescr.isValid) { stderr.writefln("Failed to parse OID"); return; } auto resp = sess.get(sysDescr); if (!resp.ok) { stderr.writefln("SNMP GET failed (status=%d errstat=%s)", resp.status, resp.errStatus); return; } foreach (v; resp.variables) writefln("%s = %s", v.oidString, v.valueString); }