News:

We really need your input in this questionnaire

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - sa_drug

#1
Спасибо огромное за помощь, все получилось!

Вот скрипт / функция backup-а конфигов по tftp для Dlink Industrial (cisco-like) Switches 1510 Series, но в целом, как шаблон, подойдет для других моделей, меняются только OID-ы.


/* 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;
#2
А не могли бы привести пример, не нахожу в документации ничего про ByteStream.
#3
Общие вопросы / [nxsnmpset]: Hex-String
July 12, 2022, 10:08:07 AM
Здравствуйте, подскажите как с помощью nxsnmpset установить значение с типом Hex-String, т.е.:
snmpset -v3 -a SHA -A password -l authPriv -u writeuser -x DES -X password 10.34.222.74 .1.3.6.1.4.1.171.14.14.1.2.1.6.1 x c0a8055d
iso.3.6.1.4.1.171.14.14.1.2.1.6.1 = Hex-STRING: C0 A8 05 5D

А вот с помощью nxsnmpset (и соответственно в NXSL) сделать подобное не получается:

nxsnmpset -v 3 -a SHA1 -A password -u writeuser-e DES -E password 10.34.222.74 .1.3.6.1.4.1.171.14.14.1.2.1.6.1 c0a8055d
SET operation failed (Wrong value)

nxsnmpset -v 3 -a SHA1 -A password -u writeuser -e DES -E password 10.34.222.74 .1.3.6.1.4.1.171.14.14.1.2.1.6.1@STRING c0a8055d
SET operation failed (Wrong value)

nxsnmpset -v 3 -a SHA1 -A password -u writeuser -e DES -E password 10.34.222.74 .1.3.6.1.4.1.171.14.14.1.2.1.6.1@IPADDR c0a8055d
SET operation failed (Wrong type)

nxsnmpset -v 3 -a SHA1 -A password -u writeuser -e DES -E password 10.34.222.74 .1.3.6.1.4.1.171.14.14.1.2.1.6.1@IPADDR 192.168.5.93
SET operation failed (Wrong type)


.1.3.6.1.4.1.171.14.14.1.2.1.6.1 - это OID коммутаторов Dlink определяющий IP адрес сервера, на который сливается конфиг.

Используется:

ii  netxms-agent:amd64                     4.1.377-1                                       amd64        NetXMS agent
ii  netxms-base:amd64                      4.1.377-1                                       amd64        NetXMS core libraries
ii  netxms-dbdrv-pgsql:amd64               4.1.377-1                                       amd64        PostgreSQL driver for netxms-server
ii  netxms-dbdrv-sqlite3:amd64             4.1.377-1                                       amd64        SQLite3 driver for netxms-server
ii  netxms-release                         1.10                                            all          Package to install apt source and gpg keyring
ii  netxms-server:amd64                    4.1.377-1                                       amd64        meta package