Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

Network Change & Configuration Management

Reply
Highlighted
Accepted Solution

Update Component Custom Field

Authority
Posts: 29
9061     0

 

This syntax seems to work updating a device custom field.

 

      $easy->device->set_custom_field(btag => "Test" );

 

How can I update a component custom field?

Highlighted

Re: Update Component Custom Field

Expert
Posts: 127
9062     0

I haven't tried this in netmri_easy, but I'd think you would just use the DevicePhysical model instead of Device.

 

-Lon.

Highlighted

Re: Update Component Custom Field

Authority
Posts: 29
9062     0

 

Doesn't seem to like:

 

  $easy->devicephysical->set_custom_field(atag => "Test" );

 

Result:

*** Error / Can't locate object method "devicephysical" via package "NetMRI_Easy" at /mnt/host/script/8270700294492131843.ccs line 81.

***
Session log does not exist since there was an unknown error.

 

I had tried a similar syntax in external:

$client->broker->devicephysical->set_custom_field(atag => "Test");

 

NetMRI::API error loading NetMRI::API::Broker::V3_0_0:Smiley Very Happyevicephysical: no such class at ./sn81.pl line 52

 

And since I really have no idea what I'm doing, I tried:


$client->remote->devicephysical->set_custom_field(atag => "Test");

 

Result:

Can't locate object method "remote" via package "NetMRI::API" at ./sn91.pl line 45.

 

 

Highlighted

Re: Update Component Custom Field

Expert
Posts: 127
9062     0

It isn't quite that simple.  I'm not seeing your entire script, but there are many components to a single device, and you are wanting to update a component.  So we first need to find the DevicePhysicalID (component ID) before we can update it.

 

Below is a script that will list out all the components for the selected device and update the custom field called "custom_current_eox_milestone_date" to November 1st.  If there was a specific component you could 'find' (or search for) the component first using the descriptor field before you updated it.

 

#!/usr/bin/perl -w
# BEGIN-SCRIPT-BLOCK
# Script-Filter: $Vendor == "Cisco" and $type in ["Router","Switch-Router","Switch"] and $sysdescr like /IOS|NX-OS/
#
# Script-Timeout: 600
# Script-Login:
# true
#
# Script-Variables:
# END-SCRIPT-BLOCK

use strict;
use warnings;
use NetMRI_Easy;

my $easy = new NetMRI_Easy;

my @physicals = $easy->broker->device_physical->index({
    DeviceID => $easy->device_id,
});

foreach my $physical (@physicals)
{
    print $physical->DevicePhysicalID,'\t',$physical->PhysicalDescr,'\r\n';
    
    $easy->broker->device_physical->update_custom_field({
        DevicePhysicalID => $physical->DevicePhysicalID,
        custom_current_eox_milestone_date => '2016-11-01'
    });
        
}

1;

 

Highlighted

Re: Update Component Custom Field

Authority
Posts: 29
9062     0

Lon,

 

That did work just as you suggested.

 

Would you happen to have an example of what updating the same field externally?

 

Thank you!

 

Highlighted

Re: Update Component Custom Field

Authority
Posts: 29
9062     0

Here my flawed script:

 

#!/usr/bin/perl
# this script finds all Cisco devices in NetMRI
use strict;
use warnings;
use NetMRI::API;

# Connect to the NetMRI.
my $client = new NetMRI::API({
api_version => '3.0',
});


my @chassis = $client->broker->DevicePhysical->find({


# find all devices where Vendor = Cisco
op_PhysicalClass => '=', val_c_PhysicalClass => 'chassis',

# find all devices where Vendor = Cisco
# op_DeviceVendor => '=', val_c_DeviceVendor => 'Cisco',


});
foreach my $chassis (@chassis)
{


$client->broker->device_physical->$chassis->set_custom_field(atag=>"Test");

};

Highlighted

Re: Update Component Custom Field

Authority
Posts: 29
9062     0

Should had tried your origninal suggestion.  This worked:

 

use strict;
use warnings;
use NetMRI::API;

# Connect to the NetMRI.
my $client = new NetMRI::API({
api_version => '3.0',
});


my @chassis = $client->broker->DevicePhysical->find({


# find all devices where Vendor = Cisco
op_PhysicalClass => '=', val_c_PhysicalClass => 'chassis',

# find all devices where Vendor = Cisco
# op_DeviceVendor => '=', val_c_DeviceVendor => 'Cisco',


});
foreach my $chassis (@chassis)
{

print $chassis->DevicePhysicalID,"\t";

$client->broker->device_physical->update_custom_field({
DevicePhysicalID=>$chassis->DevicePhysicalID,custom_atag=>"Test"});

};

Highlighted

Re: Update Component Custom Field

Techie
Posts: 1
9062     0
<?php
// no direct access
defined ('_JEXEC') or die;
class plgContentExample extends JPlugin
{
	/**
	 * Load the language file on instantiation.
	 * Note this is only available in Joomla 3.1 and higher.
	 * If you want to support 3.0 series you must override the constructor
	 *
	 * @var boolean
	 * @since <your version>
	 */
	protected $autoloadLanguage = true;
 
	/**
	 * Prepare form and add my field.
	 *
	 * @param   JForm  $form  The form to be altered.
	 * @param   mixed  $data  The associated data for the form.
	 *
	 * @return  boolean
	 *
	 * @since   <your version>
	 */
	function onContentPrepareForm($form, $data)
	{
		$app    = JFactory::getApplication();
		$option = $app->input->get('option');
 
		switch($option)
		{
			case 'com_contact' :
				if ($app->isAdmin())
				{
					JForm::addFormPath(__DIR__ . '/forms');
					$form->loadFile('contact', false);
				}
 
				return true;
		}
 
		return true;
	}
}
?>
Showing results for 
Search instead for 
Do you mean 

Recommended for You