Спасибо огромное за помощь, все получилось!
Вот скрипт / функция backup-а конфигов по tftp для Dlink Industrial (cisco-like) Switches 1510 Series, но в целом, как шаблон, подойдет для других моделей, меняются только OID-ы.
Вот скрипт / функция backup-а конфигов по tftp для Dlink Industrial (cisco-like) Switches 1510 Series, но в целом, как шаблон, подойдет для других моделей, меняются только OID-ы.
Code Select
/* 1. Create snmp transport to current node */
println ("[INFO]: Node name - " . $node->name);
transport = $node->createSNMPTransport();
if (transport == null)
{
println ( "[ERROR]: Failed to create SNMP transport" );
return -1;
}
/* 2. Generate backup name */
/* 2.1 Path prefix / Node name / Date and time manipulation */
snmpName = transport->get(".1.3.6.1.2.1.1.5.0")->printableValue;
pathPrefix = "ma-switches";
backupName = ( pathPrefix . "/" . snmpName . "/" . "backup_" . strftime("%d-%m-%Y_%H-%M", time()) . ".cfg");
println ( "[INFO]: " . backupName );
/* 2.2 Backup */
/*
.dlinkIndustrialCommon.dlinkSwSystemFileMIB.dsfMIBObjects.dsfCopyTable.dsfCopyEntry
- dsfCopyType :: 2 - Upload TFTP / 3 - Upload FTP / 5 - Download TFTP
.1.3.6.1.4.1.171.14.14.1.2.1.2.1 = INTEGER: 2
- dsfCopySrcUrl :: 'startup-config','running-config','system-log','attack-log'
.1.3.6.1.4.1.171.14.14.1.2.1.3.1 = STRING: "running-config"
- dsfCopyDstUrl :: backupName variable
.1.3.6.1.4.1.171.14.14.1.2.1.4.1 = STRING: "backup_date_time.cfg"
- dsfCopyRemoteAddrType :: 0 - unknown / 1 - ipv4 / 2 - ipv6 / 12 - dns
.1.3.6.1.4.1.171.14.14.1.2.1.5.1 = INTEGER: 1
- dsfCopyRemoteAddr :: 192.168.5.93
.1.3.6.1.4.1.171.14.14.1.2.1.6.1 = Hex-STRING: C0 A8 05 5D
- dsfCopyRowStatus
.1.3.6.1.4.1.171.14.14.1.2.1.12.1 = INTEGER: 4
*/
output = transport->set(".1.3.6.1.4.1.171.14.14.1.2.1.2.1", 2, "INTEGER");
if (!output) { println ("[ERROR]: Can't set backup method TFTP (" . $node->name . ")"); return -2 ; };
output = transport->set(".1.3.6.1.4.1.171.14.14.1.2.1.3.1", "running-config", "STRING");
if (!output) { println ("[ERROR]: Can't set backup remote source (" . $node->name . ")"); return -3 ; };
output = transport->set(".1.3.6.1.4.1.171.14.14.1.2.1.4.1", backupName, "STRING");
if (!output) { println ("[ERROR]: Can't set backup local filename (" . $node->name . ")"); return -4 ; };
output = transport->set(".1.3.6.1.4.1.171.14.14.1.2.1.5.1", 1, "INTEGER");
if (!output) { println ("[ERROR]: Can't set dest address-type to IPv4 (" . $node->name . ")"); return -5 ; };
/* https://www.netxms.org/forum/oe-oo/nxsnmpset-hex-string/ */
bs = new ByteStream();
bs->writeByte(0xC0);
bs->writeByte(0xA8);
bs->writeByte(0x05);
bs->writeByte(0x5D);
output = transport->set(".1.3.6.1.4.1.171.14.14.1.2.1.6.1", bs);
if (!output) { println ("[ERROR]: Can't set destanation IP address (" . $node->name . ")"); return -6 ; };
/* 3. Run backup */
output = transport->set(".1.3.6.1.4.1.171.14.14.1.2.1.12.1", 4, "INTEGER");
if (!output) { println ("[ERROR]: Runnig backup process failed (" . $node->name . ")"); return -12 ; };
/* 4. End */
return 0;