THIS IS A CUSTOMER GENERATED SCRIPT AND COMES WITH NO WARRANTY OR SUPPORT. PROCEED AT YOUR OWN RISK.
FEB 2020
Below is a site script that I've written to populate some items in the asset child object for devices. One item that I have recently started to add is serial number. This could then be read from a standard location like asset for the various device type.
sub config_asset_config {
my @arr;
my $devname;
my $ip;
my $sn;
my $line;
#Clear all asset data
adb_send ("mdelete * * asset *");
#Bad Community
for $line (adb_result ("mget * * sys SNMP.community value /^(?!GoodString1|GoodString2|YouGetThePicture)/")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
adb_send (sprintf ("add text %s asset Insecure_SNMP = \"<code>Community Needs Update</code>\"", $devname));
}
#SSH, Splunk, ServiceNow
for $line (adb_result ("mget * * sys ip4addr")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$ip = $arr[4] || "missing";
adb_send (sprintf ("add child %s asset", $devname));
adb_send (sprintf ("add text %s asset SSH = \"<a href='ssh://%s'>SSH</a>\"", $devname, $ip));
adb_send (sprintf ("add text %s asset Splunk = \"<a href='https://splunk.company.com/en-US/app/network/search?q=search host=%s OR host=%s' target='_blank'>Splunk</a>\"", $devname, $devname, $ip));
adb_send (sprintf ("add text %s asset ServiceNow = \"<a href='https://company.service-now.com/cmdb_ci_list.do?sysparm_query=nameSTARTSWITH%s' target='_blank'>CI</a> <a href='https://company.service-now.com/incident_list.do?sysparm_query=123TEXTQUERY321=%s' target='_blank'>INC</a> <a href='https://company.service-now.com/change_request_list.do?sysparm_query=123TEXTQUERY321=%s' target='_blank'>CHG</a>\"", $devname, $devname, $devname, $devname));
}
#Dell iDRAC service tag
for $line (adb_result ("mget * * idrac IDRAC-MIB.systemServiceTag")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$sn = $arr[4] || "missing";
$ip = adb_result (sprintf ("get %s sys ip4addr", $devname)) || "";
adb_send (sprintf ("add text %s asset Serial_Num = %s", $devname, $sn));
adb_send (sprintf ("add text %s asset Web_Console = \"<a href='https://%s' target='_blank'>Web Console</a>\"", $devname, $ip));
}
#Aruba AP
for $line (adb_result ("mget * * sys SNMP.proxy")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
my $proxy = $arr[4] || "missing";
adb_send (sprintf ("add text %s asset SNMP_Proxy = \"<a href='/dashboard?mode=device;device=%s' target='_blank'>%s</a>\"", $devname, $proxy, $proxy));
adb_send (sprintf ("add text %s asset Radios = \"<a href='/device-reporter?report=aruba.radio;mode=report;controls=device;time=last30m;limit=25;device=%s' target='_blank'>Radios</a>\"", $devname, $devname));
}
for $line (adb_result ("mget * * * WLSX-WLAN-MIB.wlanAPSerialNumber")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$sn = $arr[4] || "missing";
adb_send (sprintf ("add text %s asset Serial_Num = \"%s\"", $devname, $sn));
}
#Juniper SN
for $line (adb_result ("mget * * box JUNIPER-MIB.jnxBoxSerialNo")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$sn = $arr[4] || "missing";
adb_send (sprintf ("add text %s asset Serial_Num = \"%s\"", $devname, $sn));
}
#Juniper VC report
for $line (adb_result ("mget * * vchassis.0 JUNIPER-VIRTUALCHASSIS-MIB.jnxVirtualChassisMemberRole")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
adb_send (sprintf ("add text %s asset VC_Report = \"<a href='/device-reporter?report=juniper.vcm;mode=report;device_list=%s' target='_blank'>VC Report</a>\"", $devname, $devname));
}
#Brocade stack report
for $line (adb_result ("mget * * module.2.1 FOUNDRY-SN-AGENT-MIB.snAgentBrd2MainBrdDescription")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
adb_send (sprintf ("add text %s asset Stack = \"<a href='/device-reporter?report=brocade.stack_unit;mode=report;device_list=%s' target='_blank'>Stack</a>\"", $devname, $devname));
}
#ISIS
for $line (adb_result ("mget * * * ISIS-MIB.ip4addr")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
adb_send (sprintf ("add text %s asset ISIS = \"<a href='/device-reporter?report=generic.isis_neighbours;mode=report;controls=device;time=last8h;limit=25;device=%s' target='_blank'>ISIS</a>\"", $devname, $devname));
}
#BGP
for $line (adb_result ("mget * * * BGP4-MIB.bgpPeerAdminStatus")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
adb_send (sprintf ("add text %s asset BGP = \"<a href='/device-reporter?report=device.bgp;mode=report;controls=device;time=last8h;limit=100;device=%s' target='_blank'>BGP</a>\"", $devname, $devname));
}
#Aruba Controller
for $line (adb_result ("mget * * sys SNMPv2-MIB.sysObjectID value /^ARUBA-MIB.a(6000|7210|7240)/")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$ip = adb_result (sprintf ("get %s sys ip4addr", $devname)) || "";
adb_send (sprintf ("add text %s asset Web_Console = \"<a href='https://%s:4343' target='_blank'>Web Console</a>\"", $devname, $ip));
}
#Aruba Clearpass
for $line (adb_result ("mget * * sys SNMPv2-MIB.sysObjectID value CPPM-MIB.clearpass")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$ip = adb_result (sprintf ("get %s sys ip4addr", $devname)) || "";
adb_send (sprintf ("add text %s asset Web_Console = \"<a href='https://%s' target='_blank'>Web Console</a>\"", $devname, $ip));
}
#Silverpeak - Needs work to do
for $line (adb_result ("mget * * sys ip4addr any group Silverpeak")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$ip = adb_result (sprintf ("get %s sys ip4addr", $devname)) || "";
adb_send (sprintf ("add text %s asset Orchestrator = \"<a href='https://1.1.1.1' target='_blank'>Orchestrator</a>\"", $devname));
adb_send (sprintf ("add text %s asset Web_Console = \"<a href='https://%s' target='_blank'>Web Console</a>\"", $devname, $ip));
}
#VMWare ESXi hosts
for $line (adb_result ("mget * * sys SNMPv2-MIB.sysObjectID value VMWARE-ESX-MIB.vmwESX")) {
@arr = split (" ", $line, 5);
$devname = $arr[0];
$ip = adb_result (sprintf ("get %s sys ip4addr", $devname)) || "";
adb_send (sprintf ("add text %s asset Web_Console = \"<a href='https://%s:4343' target='_blank'>Web Console</a>\"", $devname, $ip));
my $vcpu = add_attributes (sprintf ("mget integer %s /vmguest/ VMWARE-VMINFO-MIB.vmwVmCpus", $devname));
my $pcpu = count_attributes (sprintf ("mget gauge %s /cpu/ HOST-RESOURCES-MIB.hrProcessorLoad", $devname));
if ($vcpu > $pcpu) {
adb_send (sprintf ("add text %s asset CPU_Ratio = \"<code>%s vCPU / %s CPU</code>\"", $devname, $vcpu, $pcpu));
}
my $vram = add_attributes (sprintf ("mget integer %s /vmguest/ VMWARE-VMINFO-MIB.vmwVmMemSize", $devname));
my $pram = adb_result (sprintf ("get %s host HOST-RESOURCES-MIB.hrMemorySize", $devname)) || 0;
if ($vram > $pram) {
$vram = int_metric($vram);
$pram = int_metric($pram);
adb_send (sprintf ("add text %s asset RAM_Ratio = \"<code>%s vRAM / %s RAM</code>\"", $devname, $vram, $pram));
}
}
adb_flush ();
}
Comments
0 comments
Please sign in to leave a comment.