RSA NetWitness Packets and Logs

RSA NetWitness Logs and Packets decoders are responsible for the real-time collection of network data. The decode captures data in real time and can normalize and reconstruct data for full session analysis. In addition, the decoder can collect flow and endpoint data.

Analytics & SIEM · RSA NetWitness Packets and Logs

Details

IDRSA NetWitness Packets and Logs
ProviderPartnerOne
CategoryAnalytics & SIEM
From Version5.0.0
Supported ModulesAgentix XSIAM

README

Overview

Use the RSA NetWitness Logs and Packets integration to collect and analyze network data.

This API enables additional low-level functionality for managing various system components accessible on Cortex XSOAR. Each command has several options that analyze and query NetWitness P&L packets, sessions, and logs. You can use the results as tasks in playbooks for automated analysis, or view them in the War Room.

This integration was integrated and tested with NetWitness v11.1.0.0.


Use Cases

  • Collect network data in real time for analysis.
  • Dump information for backup and duplication.

Prerequisites

Verify that you satisfy these requirements in RSA.

  • Obtain RSA NetWitness credentials.
  • Enable the RESTful API that ships with RSA Security Analytics.
    • Configure rest/config/enabled to on. This is the default.
    • The default port for communication is the default port + 100 (for example, 50105 for a Concentrator). You can change the port by setting the /rest/config/port parameter. SSL is controlled by the setting in /sys/config/ssl.

Configure RSA NetWitness Logs and Packets on Cortex XSOAR

  1. Navigate to Settings Integrations Servers & Services.
  2. Search for RSA NetWitness Packets and Logs.
  3. Click Add instance to create and configure a new integration.
    • Name: a textual name for the integration instance.
    • Appliance IP/Hostname
    • Appliance Port: Logs(50102), Packets(50104), Concentrator (50105), Broker (50103)
    • Credentials: NetWitness user credentials
    • Secure (over HTTPS) - wheter to send requests over SSL
    • Use system proxy settings
    • Expiration time
  4. Click Test to validate the URLs, token, and connection.

Commands

You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook. After you successfully execute a command, a DBot message appears in the War Room with the command details.

  1. Search pattern matches: netwitness-msearch
  2. Search: netwitness-search
  3. Query: netwitness-query
  4. Stream packets: netwitness-packets
  5. Get meta ID range: nw-sdk-session
  6. Get packet content: nw-sdk-content
  7. Get summary: nw-sdk-summary
  8. Get value count: nw-sdk-values
  9. Dump information: nw-database-dump

Search pattern matches

Search for pattern matches in multiple sessions or packets.

Base Command

netwitness-msearch

Input
Parameter Type Description
sessions string Search within these session ID ranges
packets string Search within these packet ID ranges
search string

String to search for. Can be a simple string or a query. For regular expressions, change the word “keyword” to “regex”.

Example: "select hit, pretext, posttext where keyword=’netwitness’ sp ci ds". sp = Search Packets ci = Case Insensitive ds = Decode Sessions (for example, convert email attachments before searching)

where string

Filter criteria for which sessions to search

limit uint64 Maximum number of sessions to search in this instance
flags string

Comma-separated list of one or more flag values.

Example: regex, sp, sm, si, ci, pre, post, ds

concentratorIP integer

Use the instance that is mapped to this concentrator IP

concentratorPort integer

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

 

Context Data
Path Description
NetWitness.SearchHits.hit All matching search results in NetWitness

 

Command Example

!netwitness-msearch search="ab" limit="10" flags="sp,ci"

Raw Output
[  
   {  
      "flags":1074200578,
      "results":{  
         "fields":[  
            {  
               "count":0,
               "flags":0,
               "format":65,
               "group":1,
               "id1":1,
               "id2":1,
               "type":"hit",
               "value":"ab"
            }
         ],
         "id1":1,
         "id2":1
      }
   },
   {  
      "flags":1074200578,
      "results":{  
         "fields":[  
            {  
               "count":0,
               "flags":0,
               "format":65,
               "group":2,
               "id1":2,
               "id2":2,
               "type":"hit",
               "value":"ab"
            }
         ],
         "id1":2,
         "id2":2
      }
   },
   {  
      "flags":1074200578,
      "results":{  
         "fields":[  
            {  
               "count":0,
               "flags":0,
               "format":65,
               "group":10,
               "id1":10,
               "id2":10,
               "type":"hit",
               "value":"ab"
            }
         ],
         "id1":1,
         "id2":1
      }
   },
   {  
      "flags":1074200578,
      "results":{  
         "fields":[  
            {  
               "count":0,
               "flags":0,
               "format":65,
               "group":3,
               "id1":3,
               "id2":3,
               "type":"hit",
               "value":"ab"
            }
         ],
         "id1":3,
         "id2":3
      }
   },
   {  
      "flags":1074200578,
      "results":{  
         "fields":[  
            {  
               "count":0,
               "flags":0,
               "format":65,
               "group":4,
               "id1":4,
               "id2":4,
               "type":"hit",
               "value":"ab"
            }
         ],
         "id1":4,
         "id2":4
      }
   },
   {  
      "flags":1074200578,
      "results":{  
         "fields":[  
            {  
               "count":0,
               "flags":0,
               "format":65,
               "group":7,
               "id1":7,
               "id2":7,
               "type":"hit",
               "value":"ab"
            }
         ],
         "id1":7,
         "id2":7
      }
   },
   {  
      "flags":1074200578,
      "results":{  
         "fields":[  
            {  
               "count":0,
               "flags":0,
               "format":65,
               "group":8,
               "id1":8,
               "id2":8,
               "type":"hit",
               "value":"ab"
            }
         ],
         "id1":8,
         "id2":8
      }
   },
   {  
      "flags":1074200577,
      "results":{  
         "fields":[  

         ],
         "id1":11,
         "id2":10
      }
   }
]
War Room Output


Search

Deprecated. See Search Pattern Matches.

Base Command

netwitness-search

Input
Parameter Type Description
sessions string Search within these session ID ranges
size

uint32

Maximum number of entries to return (range: 1-1677721)

search string

String to search for

concentratorIP string

Use the instance that is mapped to this concentrator IP

concentratorPort uint32 

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

 

Context Data
Path Description
NetWitness.SearchHits All matching search results in NetWitness

 


Query

Performs a query against the meta database.

Base Command

netwitness-query

Input
Parameter Type Description
id1 uint64

First Meta ID (to run the query from most recent to oldest meta, make id1 larger than id2)

id2 uint64

Final Meta ID

size uint32

Maximum number of entries to return

Default: All results

query string

Query string to use

flags string

Flags to use for query. Can be a number (bitwise mask) or comma-separated values like query-log

threshold uint64

Stops processing results after the threshold is reached (useful with select aggregate functions)

Default: No threshold

lastHours uint64

Filter for date and time

lastMinutes uint64

Filter by last minute

concentratorIP string

Use the instance that is mapped to this concentrator address

concentratorPort uint32 

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

 

Context Data
Path Description
NetWitness.Events.ipSrc Source IP
NetWitness.Events.aliasIp Destination IP
NetWitness.Events.aliasHost Hostname or FQDN
NetWitness.Events.ipDst IP Destination of event
NetWitness.Events.userSrc Source user
NetWitness.Events.userDst Destination user
NetWitness.Events.username Includes any available username metadata (source and destination) as defined by the user. This is an optional field which only appears if configured by the end user.
NetWitness.Events.service The service that created the session (if available)
NetWitness.Events.sessionid The NW Specific field that contains an NW specific ‘serial number’ of the Session - allows a user to specify a session to retrieve from a Concentrator
NetWitness.Events.deviceType System type that generated a log message (for example, SQUID, Windows, rhlinux)
NetWitness.Events.direction Traffic flow direction (for example, inbound/outbound)
NetWitness.Events.did Specific decoder a session was captured on
NetWitness.Events.ioc Endpoint specific metadata that describes malware on an endpoint

Command Example

!netwitness-query size="5" query="select*where alias.host contains 'skimresources'"

Raw Output
{  
   "flags":1074200577,
   "results":{  
      "fields":[  
         {  
            "count":0,
            "flags":0,
            "format":8,
            "group":13,
            "id1":504,
            "id2":504,
            "type":"sessionid",
            "value":"13"
         },
         {  
            "count":0,
            "flags":0,
            "format":32,
            "group":13,
            "id1":505,
            "id2":505,
            "type":"time",
            "value":1372882420
         },
         {  
            "count":0,
            "flags":0,
            "format":6,
            "group":13,
            "id1":506,
            "id2":506,
            "type":"size",
            "value":"16452"
         },
         {  
            "count":0,
            "flags":0,
            "format":6,
            "group":13,
            "id1":507,
            "id2":507,
            "type":"payload",
            "value":"13590"
         },
         {  
            "count":0,
            "flags":0,
            "format":2,
            "group":13,
            "id1":508,
            "id2":508,
            "type":"medium",
            "value":"1"
         }
      ],
      "id1":509,
      "id2":3938
   }
}
War Room Output

 

More Query Command Examples:

!netwitness-query size="5" query="select*where device.class contains 'Anti Virus'"

!netwitness-query size="5" query="select*where sessionid=1831740465537" 



Stream packets

Streams packets back based on the input parameters provided.

Base Command

netwitness-packets

Input
Parameter Type Description
op string

The operation to perform (start, cancel, processed)

{enum-one:start|cancel|processed}

sessions string

A comma-separated list of session IDs or session ID ranges (#-#) whose packets will be streamed back

packets string

A comma-separated list of packet IDs or session IDs (#&#) which will be streamed back

where string

The sessions to stream back

time1 date-time

Starting time (UTC) for when matching packets are streamed back ("2010-Apr-20 09:00:00")

time2 date-time

Ending time (UTC) for when matching packets are streamed back ("2010-Apr-20 10:00:00")

flags uint32 Additional flags as defined by the NwPackets SDK function
concentratorIP string Use the instance that is mapped to this concentrator address
concentratorPort uint32

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

render string 

Render type

Examples: pcap, logs, logs (csv), logs (xml), or logs (json)

renderToContext boolean 

If renderToContext is set to True and the render type is set to logs (json), the command will not create a file with the output. It will output to the context data.

 

Context Data

There is no context data for this command.

Command Example

!netwitness-packets sessions="1,2,3,4,5"

Raw Output

There is no raw output for this command.

War Room Output


Get meta ID range

Returns the meta ID range for the session range.

Basic Command

nw-sdk-session

Input
Parameter Type Description
id1 uint64

Starting session ID

id2 uint64

Ending session ID

concentratorIP string

Use the instance that is mapped to this concentrator IP

concentratorPort uint32

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

 

Context Data

There is no context data for this command.

Command Example

!nw-sdk-session id1=1 id2=10

Raw Output
{  
   "flags":1073938433,
   "params":{  
      "field1":"1",
      "field2":"334",
      "id1":"1",
      "id2":"10"
   }
}
War Room Output


Get packet content

Returns the packet content for a session.

Base Command

nw-sdk-content

Input
Parameter Type Description
concentratorIP string

Use the instance that is mapped to this concentrator IP

concentratorPort uint32

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

session uint64

Session ID to return.

renderType string

Render type for content (defined in NwSDK.h)

OR

One of the following render types:

text, hex, packets, web, mail, raw, rtp, voip, meta, im, files or pcap

maxSize uint64

Maximum size of the session returned (bytes). Zero is unlimited.

Default is zero.

base64 binary

If 1, encode the multipart/mixed response as base64

Default is binary

flags string

Flags for content rendering, see the SDK header file NwContent flags parameter for more info (Optional)

includeFileTypes string

Semicolon-separated list of file extensions to extract

Example: .ext1;.ext2

excludeFileTypes string

Semicolon-separated list of file extensions to exclude

Example: .ext1;.ext2

renameFileTypes string

Renames certain files from one or more extensions to another

Example: renameFileTypes=.download|.octet-stream|.program|.exe;.jpeg|.jpg

fileExt string

Extension of the saved file

where string

The sessions to stream back

subdirFileTypes string

Groups files into the specified directory

Example: documents=.doc;.xls;.pdf; images=.png;.gif;.jpg;.jpeg;

maxDirSize uint32

Deletes oldest files, when this value is exceeded by top-level directory

renderFlags uint32

Bitwise mask to control options, (see NwContentFlags in NwSDK.h)

(Optional)

 

Context Data

There is no context data for this command.

Command Example

!nw-sdk-content session="23" renderType="mail" fileExt=".zip"

Raw Output

There is no raw output for this command.

War Room Output


Get summary

Returns summary information from the databases.

Base Command

nw-sdk-summary

Input
Parameter Type Description
flags string

SDK flags - can be a number (bitwise mask) or comma-separated values like default or ignore-cache.

concentratorIP  string

Use the instance that is mapped to this concentrator IP

concentratorPort uint32 

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

 

Context Data

There is no context data for this command.

Command Example

!nw-sdk-summary

Raw Output
{  
   "flags":1073872897,
   "string":"mid1=1 mid2=3938 msize=106496 mmax=142947249029 pid1=0 pid2=0 psize=0 pmax=0 time1=336000 time2=1522264920 ptime1=0 ptime2=0 sid1=1 sid2=65 ssize=4096 smax=142947249029 stotalsize=12787062 isize=195854392 memt=8371580928 memu=3604697088 memp=213417984 hostname=NWAPPLIANCE14623 version=11.1.0.0"
}
War Room Output


Get value count

Performs a value count query and returns the matching values in a report.

Basic Command

nw-sdk-values

Input
Parameter Type Description
id1 uint64

Starting meta ID

id2 uint64

Ending meta ID

size uint32

Max number of entries to return

{range:1 to 1677721}

flags string

The flags to use for values. Can be a number (bitwise mask) or comma-separated values (for example, sessions, size, packets, aggregate, sort-total, sort-value, order-ascending, order-descending, ignore-cache, clear-cache, query-log or database-scan)

threshold uint64

Query optimization to stop processing large session counts

fieldName  

Field to retrieve values for

where string

Filter criteria for the values

aggregateFunction string

The meta field to aggregate in the aggregateFunction

min string

Limits the returned values to values higher than this

max string

Limits the returned values to values lower than this

concentratorIP string

Use the instance that is mapped to this concentrator IP

concentratorPort uint32 

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

 

Context Data
Path Description
NetWitness.Values.ipSrc Source IP
NetWitness.Values.aliasIp Destination IP
NetWitness.Values.aliasHost Hostname or FQDN
NetWitness.Values.ipDst IP Destination of the event
NetWitness.Values.userSrc Source user
NetWitness.Values.userDst Destination user
NetWitness.Values.username Includes any available username meta – both source and destination – as defined by the user. This is an optional field, which only appears if configured by the end user.
NetWitness.Values.service The service that created the session (if available)
NetWitness.Values.sessionid The NW Specific field that contains an NW specific ‘serial number’ of the session. Allows a user to specify a session to retrieve from a Concentrator
NetWitness.Values.deviceType The type of system that generated a log message (ex. SQUID / Windows / rhlinux)
NetWitness.Values.direction Traffic flow direction (for example, inbound/outbound)
NetWitness.Values.did Specific decoder a session was captured on
NetWitness.Values.ioc Endpoint specific meta which describes malware on an endpoint

 

Command Example

!nw-sdk-values size="10" fieldName="client"

Raw Output
{  
   "flags":1074200577,
   "results":{  
      "fields":[  
         {  
            "count":1,
            "flags":0,
            "format":65,
            "group":0,
            "id1":25,
            "id2":25,
            "type":"client",
            "value":"opera mail/12.11"
         },
         {  
            "count":5,
            "flags":0,
            "format":65,
            "group":0,
            "id1":13,
            "id2":63,
            "type":"client",
            "value":"mozilla/5.0"
         },
         {  
            "count":31,
            "flags":0,
            "format":65,
            "group":0,
            "id1":14,
            "id2":61,
            "type":"client",
            "value":"mozilla/4.0"
         },
         {  
            "count":2,
            "flags":0,
            "format":65,
            "group":0,
            "id1":5,
            "id2":6,
            "type":"client",
            "value":"e1e8d428-5bf1-4323-8808-d138a039102f"
         }
      ],
      "id1":0,
      "id2":0
   }
}
War Room Output


Dump information

Dumps information out of the database in nwd formatted files.

Base Command

nw-database-dump

Input
Parameter Type Description
session uint64

ID of the session to dump

type string

Dump type

{enum-one:db|nwd}

source string

Types of data to dump

Default is all data

{enum-any:s|m|p}

verbose boolean

Default is false

If true - dumps more information

file string

Filename to use for NWD type

Default: sessionid.nwd

concentratorIP string

Use the instance that is mapped to this concentrator IP

concentratorPort uint32 

Port to use with concentratorIP. 50105 (SSL/NON-SSL) for concentrator, 50103 (SSL/NON-SSL) for broker.

useSSL boolean

Send request in HTTPS instead of HTTP. By default the parameter is set to True but if your appliance is not configured to use SSL you can change it here.

 
Context Data

There is no context data for this command.

Command Example

!nw-database-dump session="1" source="m"

Raw Output
{  
   "flags":1074003969,
   "params":[  
      {  
         "MetaArray":"31",
         "dbFile":"/var/netwitness/concentrator/metadb/meta-000000001.nwmdb"
      },
      {  
         "meta.id":"1",
         "session":"1",
         "type":"sessionid",
         "value":"1"
      },
      {  
         "meta.id":"2",
         "session":"1",
         "type":"time",
         "value":"2018-Mar-27 16:05:59"
      },
      {  
         "meta.id":"3",
         "session":"1",
         "type":"size",
         "value":"1468"
      },
      {  
         "meta.id":"4",
         "session":"1",
         "type":"medium",
         "value":"32"
      },
      {  
         "meta.id":"5",
         "session":"1",
         "type":"device.type",
         "value":"rsaflow"
      },
      {  
         "meta.id":"6",
         "session":"1",
         "type":"device.class",
         "value":"Switch"
      },
      {  
         "meta.id":"7",
         "session":"1",
         "type":"alias.host",
         "value":"xxx.xxx.x.xxx"
      },
      {  
         "meta.id":"8",
         "session":"1",
         "type":"version",
         "value":"9"
      },
      {  
         "meta.id":"9",
         "session":"1",
         "type":"event.type",
         "value":"flowdata"
      },
      {  
         "meta.id":"10",
         "session":"1",
         "type":"event.desc",
         "value":"flowdata"
      },
      {  
         "meta.id":"11",
         "session":"1",
         "type":"ip.src",
         "value":"xxx.xxx.x.xxx"
      },
      {  
         "meta.id":"12",
         "session":"1",
         "type":"netname",
         "value":"private src"
      },
      {  
         "meta.id":"13",
         "session":"1",
         "type":"ip.dst",
         "value":"xxx.xxx.x.xxx"
      },
      {  
         "meta.id":"14",
         "session":"1",
         "type":"netname",
         "value":"other dst"
      },
      {  
         "meta.id":"15",
         "session":"1",
         "type":"direction",
         "value":"outbound"
      },
      {  
         "meta.id":"16",
         "session":"1",
         "type":"ip.proto",
         "value":"6"
      },
      {  
         "meta.id":"17",
         "session":"1",
         "type":"ip.dstport",
         "value":"80"
      },
      {  
         "meta.id":"18",
         "session":"1",
         "type":"tcp.flags",
         "value":"24"
      },
      {  
         "meta.id":"19",
         "session":"1",
         "type":"bytes.src",
         "value":"10"
      },
      {  
         "meta.id":"20",
         "session":"1",
         "type":"eth.src",
         "value":"xxx.xxx.x.xxx"
      },
      {  
         "meta.id":"21",
         "session":"1",
         "type":"eth.dst",
         "value":"xxx.xxx.x.xxx"
      },
      {  
         "meta.id":"22",
         "session":"1",
         "type":"event.name",
         "value":"flowdata"
      },
      {  
         "meta.id":"23",
         "session":"1",
         "type":"direction",
         "value":"inbound"
      },
      {  
         "meta.id":"24",
         "session":"1",
         "type":"event.time",
         "value":"2006-Sep-07 02:42:10"
      },
      {  
         "meta.id":"25",
         "session":"1",
         "type":"bytes",
         "value":"307"
      },
      {  
         "meta.id":"26",
         "session":"1",
         "type":"msg.id",
         "value":"rsaflow"
      },
      {  
         "meta.id":"27",
         "session":"1",
         "type":"event.cat.name",
         "value":"Other.Default"
      },
      {  
         "meta.id":"28",
         "session":"1",
         "type":"device.disc",
         "value":"100"
      },
      {  
         "meta.id":"29",
         "session":"1",
         "type":"sourcefile",
         "value":"drivebyDL_1-1.log"
      },
      {  
         "meta.id":"30",
         "session":"1",
         "type":"did",
         "value":"nwappliance27515"
      },
      {  
         "meta.id":"31",
         "session":"1",
         "type":"rid",
         "value":"1"
      }
   ]
}
War Room Output


Error Responses

Error What to do
No response generated from commands

Make sure the appliance's IP or port are correct.

401 Unauthorized

Make sure the NetWitness user credentials are correct.

400 Bad Request

Make sure the command was sent to the right appliance, and that a compatible argument is attached

404 Not Found

Make sure the appliance supports the executed command

 


Troubleshooting

When executing the !netwitness-query command and you want to use the sessionid RSA NetWitness meta key as part of the query that is passed to the query argument, please note that for any given session that Decoders, Concentrators, and Brokers appliances all maintain Session IDs which may be different. You can read more about using Session IDs here.

Configuration parameters

  • url — Server URL (e.g. http(s)://192.168.0.1) (required)
  • port — Appliance Port - Logs(50102) / Packets(50104) / Concentrator (50105) / Broker (50103) (required)
  • username — Username
  • password — Password
  • user_creds — Username
  • secure — Validate server certificate
  • proxy — Use system proxy settings
  • expiry — Expiration time

Commands (9)

  • netwitness-msearch

    Search for pattern matches in many sessions or packets

  • netwitness-packets

    Stream packets back based on the input parameters provided

  • netwitness-query

    Performs a query against the meta database

  • netwitness-search Deprecated

    Searches for matches in session/packet content

  • nw-database-dump

    Dumps information out of the database in nwd formatted files

  • nw-sdk-content

    Returns the packet content for a session

  • nw-sdk-session

    Retrieves the meta id range for the session range

  • nw-sdk-summary

    Retrieves summary information from the databases

  • nw-sdk-values

    Performs a value count query and returns the matching values for a report

var RESPONSE_TYPES = {
    'json': 'application/json',
    'html': 'text/html',
    'text': 'text/plain',
    'xml': 'text/xml',
    'octet-stream': 'application/octet-stream'
};
var API_REST_PORT = '50105';
var LAST_HOURS = 'lastHours';
var LAST_MINUTES = 'lastMinutes';
var QUERY = 'query';
var USER_NAME = params.user_creds ? params.user_creds.identifier : params.username;

var PASSWORD = (params.user_creds || params).password;


function fixUrl(base) {
    var url = base.trim();
    if (base.indexOf('http://') !== 0 && base.indexOf('https://') !== 0) {
        url = "http://" + url;
    }

    url = url.replace(/\/$/, '');

    return url;
}

var BASE_URL = getUrl(fixUrl(params.url) + ':' + params.port);

// Check if concentrator IP and/or port were provided, if yes, then the url will be changed to the assigned concentrator.
function getUrl(currentUrl){
    var urlToReturn;
    if(args && args.concentratorIP){
        // Check if port was provided, omit it if yes
        var match = args.concentratorIP.match(/(https{0,1}:\/\/?.*):/);
        urlToReturn = match ? match[1] : args.concentratorIP;
        var port = args.concentratorPort || API_REST_PORT;
        var useSSL = args.useSSL;

        if(useSSL === "true"){
            urlToReturn = urlToReturn.indexOf('https://') === -1 ? 'https://' + urlToReturn : urlToReturn;
        }
        else{
            urlToReturn = urlToReturn.indexOf('http://') === -1 ? 'http://' + urlToReturn : urlToReturn;
        }

        urlToReturn = urlToReturn + ":" + port;

        delete(args.concentratorIP);
        delete(args.concentratorPort);
    }
    else {
        urlToReturn = currentUrl;
    }

    return urlToReturn;
}

function isObjectEmpty(obj) {
    for(var key in obj) {
        if(obj.hasOwnProperty(key))
            return false;
    }
    return true;
}

/* Example transformation:
 {
    "fields": [
        {
            "count": 0,
            "flags": 0,
            "format": 8,
            "group": 13,
            "id1": 504,
            "id2": 504,
            "type": "sessionid",
            "value": "13"
        },
        {
            "count": 0,
            "flags": 0,
            "format": 32,
            "group": 13,
            "id1": 505,
            "id2": 505,
            "type": "time",
            "value": 1372882420
        },
        {
            "count": 0,
            "flags": 0,
            "format": 6,
            "group": 13,
            "id1": 506,
            "id2": 506,
            "type": "size",
            "value": "16452"
        },
        {
            "count": 0,
            "flags": 0,
            "format": 6,
            "group": 13,
            "id1": 507,
            "id2": 507,
            "type": "payload",
            "value": "13590"
        },
        {
            "count": 0,
            "flags": 0,
            "format": 2,
            "group": 13,
            "id1": 508,
            "id2": 508,
            "type": "medium",
            "value": "1"
        }
    ],
    "id1": 509,
    "id2": 3938
}

To:

{
    sessionid: 13,
    paylod: 13590,
    size: 16542,
    time: 1372882420
}

*/

function mapQueryResults(fields, queryResults) {
    var TYPE  = 'type';
    var VALUE = 'value';
    var GROUP = 'group';
    if(fields && Array.isArray(fields)) {
        fields.forEach(function (element) {
            if (element[TYPE] && element[VALUE]) {
                var index = element[GROUP] || 0;
                if(!(queryResults[index])){
                    queryResults[index] = {};
                }
                // Dot to camel case
                var type = element[TYPE].replace(/\.([a-z,A-Z,0-9])/g, function (g) {
                    return g[1].toUpperCase();
                });

                if(!(queryResults[index][type])) {
                    queryResults[index][type] = element[VALUE];
                }
                else{
                    if(!(queryResults[index][type] instanceof Array)){
                        var currValue = queryResults[index][type];
                        // Ignore duplicates
                        if(currValue !== element[VALUE]){
                            queryResults[index][type] = [currValue];
                            queryResults[index][type].push(element[VALUE]);
                        }
                    }
                    else {
                        // Ignore duplicates
                        if(queryResults[index][type].indexOf(element[VALUE]) === -1){
                            queryResults[index][type].push(element[VALUE]);
                        }
                    }
                }
            }
        });
    }
}

/*
Example transformation:
{
    "fields": [
        {
            "count": 1,
            "flags": 0,
            "format": 65,
            "group": 0,
            "id1": 25,
            "id2": 25,
            "type": "client",
            "value": "opera mail/12.11"
        },
        {
            "count": 5,
            "flags": 0,
            "format": 65,
            "group": 0,
            "id1": 13,
            "id2": 63,
            "type": "client",
            "value": "mozilla/5.0"
        },
        {
            "count": 31,
            "flags": 0,
            "format": 65,
            "group": 0,
            "id1": 14,
            "id2": 61,
            "type": "client",
            "value": "mozilla/4.0"
        },
        {
            "count": 2,
            "flags": 0,
            "format": 65,
            "group": 0,
            "id1": 5,
            "id2": 6,
            "type": "client",
            "value": "e1e8d428-5bf1-4323-8808-d138a039102f"
        }
    ],
    "id1": 0,
    "id2": 0
}

To:

[
    {
        client: opera mail/12.11
    },
    {
        client: mozilla/5.0,
    },
    {
        client: mozilla/4.0,
    },
    {
        client: e1e8d428-5bf1-4323-8808-d138a039102f
    }
]
*/

function mapArrayResults(fields, arrayResults){
    var TYPE  = 'type';
    var VALUE = 'value';
    if(fields && Array.isArray(fields)) {
        fields.forEach(function (element) {
            var currObject = {};
            // Dot to camel case ip.src => ipSrc
            // The reason for this transformation is to allow use in context
            var type = element[TYPE].replace(/\.([a-z,A-Z,0-9])/g, function (g) {
                return g[1].toUpperCase();
            });
            currObject[type] = element[VALUE];
            arrayResults.push(currObject);
        });
    }
}

function extractFromData(data, mapper, results){
    if (Array.isArray(data)) {
        data.forEach(function (element) {
            var fields = dq(element, 'results.fields');
            mapper(fields, results);
        });
    } else if ((typeof data) ==='object') {
        var fields = dq(data, 'results.fields');
        mapper(fields, results);
    }
}

function buildQueryMdAndContext(response) {
    var data = parseResponse(response);

    var queryResults = {};
    extractFromData(data, mapQueryResults, queryResults);
    var flatQueryResult = [];
    if(!isObjectEmpty(queryResults)) {
        for(var key in queryResults) {
            flatQueryResult.push(queryResults[key]);
        }
        var hr = tableToMarkdown(command, flatQueryResult);
        return {
            Type: entryTypes.note,
            Contents: data,
            ContentsFormat: formats.json,
            HumanReadable: hr,
            EntryContext: {
                'NetWitness.Events': flatQueryResult
            },
            ReadableContentsFormat: formats.markdown
        };
    } else {
        return "No results found.";
    }
}

function buildMSearchMdAndContext(response) {
    var data = parseResponse(response);

    var queryResults = {};
    extractFromData(data, mapQueryResults, queryResults);
    var flatQueryResult = [];
    if(!isObjectEmpty(queryResults)) {
        for(var key in queryResults) {
            flatQueryResult.push(queryResults[key]);
        }
        var hr = tableToMarkdown(command, flatQueryResult);
        return {
            Type: entryTypes.note,
            Contents: data,
            ContentsFormat: formats.json,
            HumanReadable: hr,
            EntryContext: {
                'NetWitness.SearchHits': flatQueryResult
            },
            ReadableContentsFormat: formats.markdown
        };
    } else {
        return "No results found.";
    }
}

function buildValuesMdAndContext(response) {
    var data = parseResponse(response);

    var arrayResults = [];
    extractFromData(data, mapArrayResults, arrayResults);
    if(arrayResults.length !== 0) {
    var typeDict = {};
            for(var index in arrayResults){
                var type = Object.keys(arrayResults[index])[0];
                if(!typeDict[type]){
                    typeDict[type] = [];
                }

                typeDict[type].push(arrayResults[index][type]);
            }
            var arr = [];
            var maxLength = 0;
            for(var key in typeDict){
                if(maxLength < typeDict[key].length){
                    maxLength = typeDict[key].length;
                }
            }

            for(var i = 0; i < maxLength; i++){
                var currObj = {};
                for(var key in typeDict){
                    currObj[key] = typeDict[key][i];
                }
                if(!isObjectEmpty(currObj)){
                    arr.push(currObj);
                }
            }

            var hr = tableToMarkdown(command, arr);
            return {
                Type: entryTypes.note,
                Contents: data,
                ContentsFormat: formats.json,
                HumanReadable: hr,
                EntryContext: {
                    'NetWitness.Values': arrayResults
                },
                ReadableContentsFormat: formats.markdown
            };
    } else {
        return "No results found.";
    }
}

function buildTimelineMdAndContext(response) {
    var data = parseResponse(response);

    var arrayResults = [];
    extractFromData(data, mapArrayResults, arrayResults);
    if(arrayResults.length !== 0) {
        var hr = tableToMarkdown(command, arrayResults);
        return {
            Type: entryTypes.note,
            Contents: data,
            ContentsFormat: formats.json,
            HumanReadable: hr,
            EntryContext: {
                'NetWitness.Timeline': arrayResults
            },
            ReadableContentsFormat: formats.markdown
        };
    } else {
        return "No results found.";
    }
}
function buildNodeMdAndContext(response){
    var data = parseResponse(response);
    var nodes = data.nodes ? data.nodes : [data.node];

    return {
        Type: entryTypes.note,
        Contents: nodes,
        ContentsFormat: formats.json,
        HumanReadable: tableToMarkdown(command, nodes),
        EntryContext: {
            'NetWitness.Node(val.handle==obj.handle)' : nodes
        },
        ReadableContentsFormat: formats.markdown
    };
}

function buildStringMdAndContext(response){
    var data = parseResponse(response);
    var string = data.string;
    var md =  '### Results for ' + command + ':\n' + string;
    return {
        Type: entryTypes.note,
        Contents: data,
        ContentsFormat: formats.json,
        HumanReadable: md
    };
}

function buildParamsMd(response){
    var data = parseResponse(response);
    var resultParams= data.params;

    return {
        Type: entryTypes.note,
        Contents: data,
        ContentsFormat: formats.json,
        HumanReadable: tableToMarkdown(command, resultParams)
    };
}

function buildDatabaseMetaMdContext(response){
    var data = parseResponse(response);
    var resultParams = data.params;
    if(!resultParams || resultParams.length === 0){
        return 'No results found';
    }

    // First element of the response
    var metaArray = resultParams[0]['MetaArray'];
    var dbFile = resultParams[0]['dbFile'];

    results = {};

    mapQueryResults(resultParams, results);
    var flattenedResult = [];
    for(var key in results){
        results[key]['MetaArray'] = metaArray;
        results[key]['dbFile'] = dbFile;
        flattenedResult.push(results[key]);
    }

    return {
        Type: entryTypes.note,
        Contents: data,
        ContentsFormat: formats.json,
        HumanReadable: tableToMarkdown('Database dump meta', flattenedResult),
        EntryContext: {
            'NetWitness.DatabaseDump(val.sessionid == obj.sessionid)': flattenedResult
        },
        ReadableContentsFormat: formats.markdown
    };
}

function parseResponse(resp, isXml) {
    if (resp.StatusCode === 200) {
        try {
            var body = resp.Body;
            if(isXml){
                body = x2j(body);
            }
            var res = JSON.parse(body);

            return res;
        } catch (e) {
            return body;
        }
    } else {
        err = resp.Status;
        if (resp.Body) {
            err += '\n' + resp.Body;
        }
        throw err;
    }
}

function createFileEntry(data, extension){
    var currentTime = new Date();
    var fileName = command + '_at_' + currentTime.getTime();
    if(extension){
        fileName += extension;
    }

    return {
        Type: 3,
        FileID: saveFile(data),
        File: fileName,
        Contents: fileName
    };
}

function parseDownloadResponse(resp) {
    if (resp.StatusCode === 200) {
        try {
            var extension;
            if(args && args.fileExt){
                extension = args.fileExt;
            }
            if (args.renderToContext === "true" && args.render === "application/json"){
                var jsonstr = JSON.parse(resp.Body);
                return {
                    Type: entryTypes.note,
                    Contents: jsonstr,
                    ContentsFormat: formats.json,
                    HumanReadable: jsonstr["logs"],
                    ReadableContentsFormat: formats.json,
                    EntryContext: {
                        'NetWitness.Packets': jsonstr["logs"]
                    }
                };
            } else{
                return createFileEntry(resp.Bytes, extension);
            }
        } catch (e) {
            return e;
        }
    } else {
        err = resp.Status;
        if (resp.Body) {
            err += '\n' + resp.Body;
        }
        throw err;
    }
}

function handleTimeFilter(args) {
    if(LAST_HOURS in args || LAST_MINUTES in args) {
        var now = new Date();
        var dt = new Date();
        if (args[LAST_HOURS]) {
            dt.setHours(dt.getHours() - parseInt(args[LAST_HOURS]))
        }
        if (args[LAST_MINUTES]) {
            dt.setMinutes(dt.getMinutes() - parseInt(args[LAST_MINUTES]))
        }
        var buildDateFormat = function () {
            return dt.toISOString().slice(0,19).replace('T',' ') + '"-"' + now.toISOString().slice(0,19).replace('T',' ') + '"';
        };
        //if query is empry string
        if(!args || !args[QUERY]) {
            args[QUERY] = 'select * where time = "' + buildDateFormat();
        }
        //query must have select statement
        else if(args[QUERY].toLowerCase().indexOf('select') > -1) {
            sql_query = args[QUERY].toLowerCase().split('group by');

            if (sql_query[0].toLowerCase().indexOf('where') > -1)
                args[QUERY] = sql_query[0] + ' && time = "' + buildDateFormat();
            else
                args[QUERY] = sql_query[0] + ' where time = "' + buildDateFormat();

            if (sql_query.length > 1)
                args[QUERY] += ' group by ' + sql_query[1].trim();
        }
    }
}

function encodeParams(p) {
    var q = '';
    if (p) {
        var argsToIgnore = {
            responseType: true,
            using: true
        };
        handleTimeFilter(p);
        var keys = Object.keys(p);
        if (keys.length > 0) {
            q = '&';
            for (var i = 0; i < keys.length; i++) {
                if (argsToIgnore[keys[i]]) {
                    continue;
                } else if (i !== 0) {
                    q += '&';
                }
                q += encodeURIComponent(keys[i]) + '=' + encodeURIComponent(p[keys[i]]);
            }
        }
    }
    return q;
}

function doReq(method, path, args, responseType, body) {
    var parametersUrl = encodeParams(args);
    var fullUrl = BASE_URL + path + parametersUrl;
    if(responseType){
        fullUrl += ('&force-content-type=' + responseType);
    }

    if (params.expiry) {
        fullUrl += '&expiry=' + params.expiry;
    }

    var res = http(
        fullUrl,
        {
            Method: method,
            Username: USER_NAME,
            Password: PASSWORD,
            Accept: responseType || '',
            Body: body || ''
        },
        !params.secure,
        params.proxy
    );

    if (res.StatusCode !== 200 && res.StatusCode !== 201) {
        throw 'Failed to perform request to: ' + fullUrl + '. StatusCode: ' + res.StatusCode + '. Status: ' + res.Status + '. Error: ' + res.Body;
    }

    return res;
}

function decoderImport(path) {
    var fileParam = args.entryID ? args.entryID : args.fileID;
    var fullUrl = BASE_URL + path;
    var res = httpMultipart(
        fullUrl,
        fileParam,
        { // HTTP Request Headers
            Method: 'POST',
            ContentType: 'appliaction/json',
            Accept: 'application/json',
            Username: USER_NAME,
            Password: PASSWORD
        },
        null,
        !params.secure,
        params.proxy
    );

    var data = parseResponse(res, true);

    return {
        Type: entryTypes.note,
        Contents: data,
        ContentsFormat: formats.json,
        HumanReadable: tableToMarkdown(command, data.import.data)
    };

}

var commandToPath = {
    'netwitness-msearch': '/sdk?msg=msearch',
    'netwitness-search': '/sdk?msg=search',
    'netwitness-query': '/sdk?msg=query',
    'netwitness-packets': '/sdk/packets?',
    'nw-sdk-session': '/sdk?msg=session',
    'nw-sdk-cancel': '/sdk?msg=cancel',
    'nw-sdk-query': '/sdk?msg=query',
    'nw-sdk-validate': '/sdk?msg=validate',
    'nw-sdk-aliases': '/sdk?msg=aliases',
    'nw-sdk-content': '/sdk/?msg=content',
    'nw-sdk-ls': '/sdk?msg=ls',
    'nw-sdk-count': '/sdk?msg=count',
    'nw-sdk-timeline': '/sdk?msg=timeline',
    'nw-sdk-mon': '/sdk?msg=mon',
    'nw-sdk-stopMon': '/sdk?msg=stopMon',
    'nw-sdk-msearch': '/sdk?msg=msearch',
    'nw-sdk-precache': '/sdk?msg=precache',
    'nw-sdk-delCache': '/sdk?msg=delCache',
    'nw-sdk-info': '/sdk?msg=info',
    'nw-sdk-search': '/sdk?msg=search',
    'nw-sdk-language': '/sdk?msg=language',
    'nw-sdk-packets': '/sdk?msg=packets',
    'nw-sdk-summary': '/sdk?msg=summary',
    'nw-sdk-reconfig': '/sdk?msg=reconfig',
    'nw-sdk-values': '/sdk?msg=values',
    'nw-sdk-xforms': '/sdk?msg=xforms',
    'nw-database-info': '/database?msg=info',
    'nw-database-count': '/database?msg=count',
    'nw-database-dbState': '/database?msg=dbState',
    'nw-database-dump': '/database?msg=dump',
    'nw-database-hashnw-loInfo': '/database?msg=hashInfo',
    'nw-database-resetMax': '/database?msg=resetMax',
    'nw-database-optimize': '/database?msg=optimize',
    'nw-database-reconfig': '/database?msg=reconfig',
    'nw-database-ls': '/database?msg=ls',
    'nw-database-timeRoll': '/database?msg=timeRoll',
    'nw-database-stopMon': '/database?msg=stopMon',
    'nw-database-manifest': '/database?msg=manifest',
    'nw-database-wipe': '/database?msg=wipe',
    'nw-database-sizeRoll': '/database?msg=sizeRoll',
    'nw-database-mon': '/database?msg=mon',
    'nw-decoder-reset': '/decoder?msg=reset',
    'nw-decoder-info': '/decoder?msg=info',
    'nw-decoder-reconfig': '/decoder?msg=reconfig',
    'nw-decoder-agg': '/decoder?msg=agg',
    'nw-decoder-stop': '/decoder?msg=stop',
    'nw-decoder-count': '/decoder?msg=count',
    'nw-decoder-start': '/decoder?msg=start',
    'nw-decoder-meta': '/decoder?msg=meta',
    'nw-decoder-ls': '/decoder?msg=ls',
    'nw-decoder-stopMon': '/decoder?msg=stopMon',
    'nw-decoder-resetMax': '/decoder?msg=resetMax',
    'nw-decoder-whoAgg': '/decoder?msg=whoAgg',
    'nw-decoder-logStats': '/decoder?msg=logStats',
    'nw-decoder-select': '/decoder?msg=select',
    'nw-decoder-mon': '/decoder?msg=mon',
    'nw-index-ls': '/index?msg=ls',
    'nw-index-mon': '/index?msg=mon',
    'nw-index-save': '/index?msg=save',
    'nw-index-info': '/index?msg=info',
    'nw-index-drop': '/index?msg=drop',
    'nw-index-count': '/index?msg=count',
    'nw-index-values': '/index?msg=values',
    'nw-index-profile': '/index?msg=profile',
    'nw-index-stopMon': '/index?msg=stopMon',
    'nw-index-inspect': '/index?msg=inspect',
    'nw-index-language': '/index?msg=language',
    'nw-index-reconfig': '/index?msg=reconfig',
    'nw-index-sizeRoll': '/index?msg=sizeRoll',
    'nw-decoderParsers-ls': '/decoder/parsers?msg=ls',
    'nw-decoderParsers-mon': '/decoder/parsers?msg=mon',
    'nw-decoderParsers-feed': '/decoder/parsers?msg=feed',
    'nw-decoderParsers-info': '/decoder/parsers?msg=info',
    'nw-decoderParsers-count': '/decoder/parsers?msg=count',
    'nw-decoderParsers-schema': '/decoder/parsers?msg=schema',
    'nw-decoderParsers-reload': '/decoder/parsers?msg=reload',
    'nw-decoderParsers-upload': '/decoder/parsers?msg=upload',
    'nw-decoderParsers-delete': '/decoder/parsers?msg=delete',
    'nw-decoderParsers-stopMon': '/decoder/parsers?msg=stopMon',
    'nw-decoderParsers-devices': '/decoder/parsers?msg=devices',
    'nw-decoderParsers-content': '/decoder/parsers?msg=content',
    'nw-decoderParsers-ipdevice': '/decoder/parsers?msg=ipdevice',
    'nw-decoderParsers-iptmzone': '/decoder/parsers?msg=iptmzone',
    'nw-logs-ls': '/logs?msg=ls',
    'nw-logs-mon': '/logs?msg=mon',
    'nw-logs-pull': '/logs?msg=pull',
    'nw-logs-info': '/logs?msg=info',
    'nw-logs-count': '/logs?msg=count',
    'nw-logs-stopMon': '/logs?msg=stopMon',
    'nw-logs-download': '/logs?msg=download',
    'nw-logs-timeRoll': '/logs?msg=timeRoll',
    'nw-sys-ls': '/sys?msg=ls',
    'nw-sys-mon': '/sys?msg=mon',
    'nw-sys-save': '/sys?msg=save',
    'nw-sys-info': '/sys?msg=info',
    'nw-sys-count': '/sys?msg=count',
    'nw-sys-caCert': '/sys?msg=caCert',
    'nw-sys-stopMon': '/sys?msg=stopMon',
    'nw-sys-shutdown': '/sys?msg=shutdown',
    'nw-sys-fileEdit': '/sys?msg=fileEdit',
    'nw-sys-peerCert': '/sys?msg=peerCert',
    'nw-sys-servCert': '/sys?msg=servCert',
    'nw-sys-statHist': '/sys?msg=statHist',
    'nw-users-ls': '/users?msg=ls',
    'nw-users-mon': '/users?msg=mon',
    'nw-users-info': '/users?msg=info',
    'nw-users-auths': '/users?msg=auths',
    'nw-users-count': '/users?msg=count',
    'nw-users-delete': '/users?msg=delete',
    'nw-users-unlock': '/users?msg=unlock',
    'nw-users-stopMon': '/users?msg=stopMon',
    'nw-users-addOrMod': '/users?msg=addOrMod',
    'nw-concentrator-ls': '/concentrator?msg=ls',
    'nw-concentrator-add': '/concentrator?msg=add',
    'nw-concentrator-mon': '/concentrator?msg=mon',
    'nw-concentrator-meta': '/concentrator?msg=meta',
    'nw-concentrator-info': '/concentrator?msg=info',
    'nw-concentrator-help': '/concentrator?msg=help',
    'nw-concentrator-stop': '/concentrator?msg=stop',
    'nw-concentrator-edit': '/concentrator?msg=edit',
    'nw-concentrator-reset': '/concentrator?msg=reset',
    'nw-concentrator-count': '/concentrator?msg=count',
    'nw-concentrator-start': '/concentrator?msg=start',
    'nw-concentrator-delete': '/concentrator?msg=delete',
    'nw-concentrator-whoAgg': '/concentrator?msg=whoAgg',
    'nw-concentrator-status': '/concentrator?msg=status',
    'nw-concentrator-stopMon': '/concentrator?msg=stopMon',
    'nw-concentrator-reconfig': '/concentrator?msg=reconfig',
    'nw-concentrator-resetMax': '/concentrator?msg=resetMax',
    'nw-broker-ls': '/broker?msg=ls',
    'nw-broker-add': '/broker?msg=add',
    'nw-broker-mon': '/broker?msg=mon',
    'nw-broker-meta': '/broker?msg=meta',
    'nw-broker-info': '/broker?msg=info',
    'nw-broker-help': '/broker?msg=help',
    'nw-broker-stop': '/broker?msg=stop',
    'nw-broker-edit': '/broker?msg=edit',
    'nw-broker-reset': '/broker?msg=reset',
    'nw-broker-count': '/broker?msg=count',
    'nw-broker-start': '/broker?msg=start',
    'nw-broker-delete': '/broker?msg=delete',
    'nw-broker-whoAgg': '/broker?msg=whoAgg',
    'nw-broker-status': '/broker?msg=status',
    'nw-broker-stopMon': '/broker?msg=stopMon',
    'nw-broker-reconfig': '/broker?msg=reconfig',
    'nw-broker-resetMax': '/broker?msg=resetMax'
};


// The command input arg holds the command sent from the user.
switch (command) {
    // This is the call made when pressing the integration test button.
    case 'test-module':
        doReq('GET', '/sdk?msg=help&op=messages');
        return true;
    case 'nw-decoder-import':
        return decoderImport('/decoder/import');
    case 'netwitness-packets':
        return parseDownloadResponse(doReq('GET', commandToPath[command], args));
    case 'nw-sdk-content':
        return parseDownloadResponse(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['octet-stream']));
    case 'netwitness-msearch':
    case 'netwitness-search':
        return buildMSearchMdAndContext(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
    case 'netwitness-query':
        return buildQueryMdAndContext(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
    case 'nw-sdk-timeline':
        return buildTimelineMdAndContext(doReq('GET', commandToPath[command], RESPONSE_TYPES['json']));
    case 'nw-sdk-values':
        return buildValuesMdAndContext(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
    case 'nw-sdk-info':
    case 'nw-sdk-ls':
    case 'nw-broker-ls':
    case 'nw-concentrator-ls':
    case 'nw-database-info':
    case 'nw-database-ls':
    case 'nw-decoder-info':
    case 'nw-decoder-ls':
    case 'nw-decoderParsers-info':
    case 'nw-decoderParsers-ls':
    case 'nw-index-info':
    case 'nw-index-ls':
    case 'nw-logs-info':
    case 'nw-logs-ls':
    case 'nw-sys-info':
    case 'nw-sys-ls':
    case 'nw-users-info':
    case 'nw-users-ls':
        return buildNodeMdAndContext(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
    case 'nw-decoderParsers-ipdevice':
    case 'nw-sdk-validate':
    case 'nw-users-unlock':
    case 'nw-sdk-summary':
        return buildStringMdAndContext(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
    case 'nw-sdk-session':
    case 'nw-logs-pull':
    case 'nw-decoder-logStats':
        return buildParamsMd(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
    case 'nw-database-dump':
        return buildDatabaseMetaMdContext(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
    default:
        return parseResponse(doReq('GET', commandToPath[command], args, RESPONSE_TYPES['json']));
}