Infoblox Exchange Cybersecurity Roadshow 2020 – Join us!
North America | Europe | Middle East/Africa | Asia-Pacific

Network Change & Configuration Management

Reply
Highlighted
Accepted Solution

Retrieving status output of a NetMRI script ?

Authority
Posts: 41
5544     0

I'm wrtitting a script using


my $job_id = $client->broker->script->run({
name => $script_name,
device_ids => $device_id,
'$commands_to_be_executed' => $file
})->{JobID};

 

The output of this broker->script-run is

OUTPUTS
JobID: Integer
The JobID of the running script.

status: String
The status of the job, if the call input wait parameter had a non zero value. Status Pending or Running indicates the call timed out and the job is still in processing.

payload: String
The JSON payload of the script output, if any. Only set if Status is set and its value is

 

Can some one please advice how do I access status and payload?

 

Nidhi

~

 

 

Re: Retrieving status output of a NetMRI script ?

Adviser
Posts: 353
5545     0
Instead, do:


my $response = $client->broker->script->run({
name => $script_name,
device_ids => $device_id,
'$commands_to_be_executed' => $file
});

my $job_id = $response->{JobID};
my $status = $response->{status};

etc.

Re: Retrieving status output of a NetMRI script ?

Authority
Posts: 41
5545     0

John,

 

Thanks a bunch!!

I got the output Job_id. status and payload came out undefined. Thats ok for now I guess its not defined in the while creating the instance (maybe)

 

Now I want to grab the Job_id of the script running above by

 

my $job_res = $client->broker->job->show({id => $job_id}); # $job_id retreived from above script->run query

my $JOB = $job_res->{job};

 

printing $JOB, I'm getting 

NetMRI::API::Remote::V3_0_0::Job=HASH(0x2f5b170)

 

when I'm accessing its methods as 

print $JOB->status; $JOB->read_payload( $device_id )

 

I'm getting

SERVER general/file-not-found No such file or directory - The specified job file (output.log) could not be found.

 

 

 Please advcie

Nidhi

Re: Retrieving status output of a NetMRI script ?

Adviser
Posts: 353
5545     0
Did you use the write_payload call in the script that is being executed? That’s what the read_payload tries to decode. If you just want to see all the files, use the ”job_files” API call.

Re: Retrieving status output of a NetMRI script ?

Authority
Posts: 41
5545     0

John

 

No I didn't define anything as write_payload all I wanted to see the script result.

For exp : result of 'show version' (which I can see in netMRI GUI but not as script result (cli)

also how do I verify that my job ran successfully.

Staus?

 

Though I got my status and other attributes of Remote:Job API by

print "STATUS ", $remote->Status,"\nNAME ", $remote->name,"\nTYPE ",$remote->Type,"\n";

 

STATUS Running
NAME Run Now [XYZ]
TYPE script

 

I still have to scehdule it using JobSpecification API.

 

Thanks

Nidhi

Re: Retrieving status output of a NetMRI script ?

Adviser
Posts: 353
5545     0
Ok, it’s a little more complicated than just jobs and job specifications. A job is actually the runtime instantiation of a specification, as I described below. But a specification may include many devices (or groups) as targets for the job. The individual run of the script against a specific device is called a ”job detail”. So, you would call the index method of the Job Detail broker and pass the JobID and/or DeviceID. The ”Status” there will show the status for the specific device, whereas the ”Status” of the Job is for the entire run against all devices.

Re: Retrieving status output of a NetMRI script ?

Authority
Posts: 41
5545     0

Hi John

 

As per your last reply I made following changes in my script , looks like my instance is created but oddly enough I'm still not able to print the status of job_spacification I created.

I used serach instead of index as I didnt see Status as any field in Index.

 

$remote = $client->broker->job_detail->search({job_specification_id => $job_id});  ##working

 

print("Remote Instance Created\n") if ($remote);                                   ## working

 

print "Status = ",$remote->Status,"\n";    ### not working

Error: Can't call method "Status" on unblessed reference at xyz_scheduled.pl line 142, <STDIN> line 1.

 

I'm using job_specification broker becase this one has scheduler.

Although I'm able to create a scehduled job on my device I'm using device_id,can't used group_ids as nature of my template is specifc to each device.

 

Can you please advice?

Nidhi

Re: Retrieving status output of a NetMRI script ?

Authority
Posts: 41
5545     0

Actaully I figured.

 

I got it correct as

print "Status = ",$remote->{Status},"\n"; 

 

But its blank.. Why? Smiley Frustrated

Spoiler
 

 

Re: Retrieving status output of a NetMRI script ?

Adviser
Posts: 353
5545     0
There are three levels job spec -> job -> job detail. Change:


$remote = $client->broker->job_detail->search({job_specification_id => $job_id}); ##working

to


@details = $client->broker->job_detail->search({job_id => $job_id}); ##working

and it will be a list of individual, per-device records for the job.

Re: Retrieving status output of a NetMRI script ?

[ Edited ]
Authority
Posts: 41
5545     0

This is what I tried my script with especially with broker->JobDetail for serach method


@details = $client->broker->job_detail->search({
# JobID => $job_id
DeviceID => $device_id,
# job_specification_id => $job_id
});

 

I only got my status back as  when I ran it with DeviceID and I'm assuming its the status of the device. I got 43 results assuing this device is there in 43 job instances.


Status OK
*****************************
Status OK

 

Still not sure why job_specification_id => $job_id gave me nothing. I printed out my @device and it came null.

Though I pretty much got what I needed but still confused!Woman Frustrated

 

Re: Retrieving status output of a NetMRI script ?

Authority
Posts: 41
5545     0

Just figured and got my script working by making the right broker call as, where id is created when job specification is created in the first part of the script.

 

$remote = $client->broker->job_detail->search({job_specification_id => $job_id});
 @details = $client->broker->job_specification->index({
id => $job_id,
 select => [qw(job_type category)],
});

 

Unfortunately I ddint find 'Status' of job specifcation in any of the query methods but at least I got my script straight wothout breaking and erroring out.

 

Thanks for all your help!

 

Nidhi

Re: Retrieving status output of a NetMRI script ?

Adviser
Posts: 353
5545     0
Sure. Just be careful that you don’t mix job_specification_id and job_id. They will be different. Say you have a specification that includes a schedule to run the job hourly. After three hours, you will have three different job_ids, but they will ALL have the same job_specification_id.

John
Showing results for 
Search instead for 
Do you mean 

Recommended for You