2024-07-04 06:07:17 -07:00
import type { INodeProperties , IExecuteFunctions , IDataObject } from 'n8n-workflow' ;
import { updateDisplayOptions } from '../../../../../utils/utilities' ;
import { splunkApiJsonRequest } from '../../transport' ;
import { populate , setReturnAllOrLimit } from '../../helpers/utils' ;
import { searchJobRLC } from '../../helpers/descriptions' ;
2021-09-28 11:50:15 -07:00
2024-07-04 06:07:17 -07:00
const properties : INodeProperties [ ] = [
searchJobRLC ,
2021-09-28 11:50:15 -07:00
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
default : false ,
description : 'Whether to return all results or only up to a given limit' ,
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
default : 50 ,
description : 'Max number of results to return' ,
typeOptions : {
minValue : 1 ,
} ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
returnAll : [ false ] ,
2021-09-28 11:50:15 -07:00
} ,
} ,
} ,
{
displayName : 'Filters' ,
name : 'filters' ,
type : 'collection' ,
placeholder : 'Add Filter' ,
default : { } ,
options : [
{
displayName : 'Key-Value Match' ,
name : 'keyValueMatch' ,
2022-08-17 08:50:24 -07:00
description :
'Key-value pair to match against. Example: if "Key" is set to <code>user</code> and "Field" is set to <code>john</code>, only the results where <code>user</code> is <code>john</code> will be returned.' ,
2021-09-28 11:50:15 -07:00
type : 'fixedCollection' ,
default : { } ,
placeholder : 'Add Key-Value Pair' ,
options : [
{
displayName : 'Key-Value Pair' ,
name : 'keyValuePair' ,
values : [
{
displayName : 'Key' ,
name : 'key' ,
description : 'Key to match against' ,
type : 'string' ,
default : '' ,
} ,
{
displayName : 'Value' ,
name : 'value' ,
2022-06-03 10:23:49 -07:00
description : 'Value to match against' ,
2021-09-28 11:50:15 -07:00
type : 'string' ,
default : '' ,
} ,
] ,
} ,
] ,
} ,
] ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
2024-07-29 05:27:23 -07:00
placeholder : 'Add option' ,
2021-09-28 11:50:15 -07:00
default : { } ,
options : [
{
displayName : 'Add Summary to Metadata' ,
name : 'add_summary_to_metadata' ,
description : 'Whether to include field summary statistics in the response' ,
type : 'boolean' ,
default : false ,
} ,
] ,
} ,
] ;
2024-07-04 06:07:17 -07:00
const displayOptions = {
show : {
resource : [ 'search' ] ,
operation : [ 'getResult' ] ,
} ,
} ;
export const description = updateDisplayOptions ( displayOptions , properties ) ;
export async function execute (
this : IExecuteFunctions ,
i : number ,
) : Promise < IDataObject | IDataObject [ ] > {
// https://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTsearch#search.2Fjobs.2F.7Bsearch_id.7D.2Fresults
const searchJobId = this . getNodeParameter ( 'searchJobId' , i , '' , { extractValue : true } ) as string ;
const qs = { } as IDataObject ;
const filters = this . getNodeParameter ( 'filters' , i ) as IDataObject & {
keyValueMatch ? : { keyValuePair ? : { key : string ; value : string } } ;
} ;
const options = this . getNodeParameter ( 'options' , i ) ;
const keyValuePair = filters ? . keyValueMatch ? . keyValuePair ;
if ( keyValuePair ? . key && keyValuePair ? . value ) {
qs . search = ` search ${ keyValuePair . key } = ${ keyValuePair . value } ` ;
}
populate ( options , qs ) ;
setReturnAllOrLimit . call ( this , qs ) ;
const endpoint = ` /services/search/jobs/ ${ searchJobId } /results ` ;
const returnData = await splunkApiJsonRequest . call ( this , 'GET' , endpoint , { } , qs ) ;
return returnData ;
}