Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

METRON-1638: Retrieve Pcap results in pdml format#1120

Closed
merrimanr wants to merge 57 commits intoapache:feature/METRON-1554-pcap-query-panelfrom
merrimanr:METRON-1638
Closed

METRON-1638: Retrieve Pcap results in pdml format#1120
merrimanr wants to merge 57 commits intoapache:feature/METRON-1554-pcap-query-panelfrom
merrimanr:METRON-1638

Conversation

@merrimanr
Copy link
Contributor

@merrimanr merrimanr commented Jul 19, 2018

Contributor Comments

This PR adds a REST endpoint that returns pcap query results for the specified page in PDML format (serialized as json instead of xml). This will allow us to display pcap information in the Alerts UI.

A new getPdml method was added to the PcapService. This function gets a HDFS input stream given a path that's looked up by username, job id and page number. A Java Process object calls out to a pcap_to_pdml.sh script that wraps a simple tshark command. The HDFS inputs stream is connected to standard in of the script and PDML results are read from the process output stream. Jackson is then used to convert the output xml to json and returned.

Changes Included

  • A new PDML endpoint that accepts a job id and page number and returns PDML json for that page
  • A new PcapService getPath method that returns an HDFS path given a username, job id and page number
  • A new PcapService method described above
  • Annotated Jackson Javabean classes for transforming PDML xml to json
  • A pcap_to_pdml.sh script that wraps a simple tshark command and can be extended as needed
  • A new script path Spring property that can be changed to point to a different script location
  • Unit and integration tests

Testing

This has been tested in full dev. Testing instructions are as follows:

  1. Spin up full dev
  2. Create the HDFS directories specified in application.yml
  • /apps/metron/pcap/input
  • /apps/metron/pcap/interim
  • /apps/metron/pcap/output
  1. Put pcap data in /apps/metron/pcap/input
  2. Run a fixed pcap query to generate results:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "endTimeMs": 1458240269424,
  "startTimeMs": 1458240269419
}' 'http://node1:8082/api/v1/pcap/fixed'
  1. Monitor the job with the get status endpoint until the job has SUCCEEDED and returns a pageTotal:
{
  "jobId": "job_1532012905403_0001",
  "jobStatus": "SUCCEEDED",
  "description": "map: 20.0%, reduce: 0.0%",
  "percentComplete": 100,
  "pageTotal": 2
}
  1. Attempt to get PDML results using the job id and page number:
curl -X GET --header 'Accept: application/json' 'http://node1:8082/api/v1/pcap/job_1532012905403_0001/pdml?page=1'

You should get an error message that clearly states wireshark is missing:

{
  "responseCode": 500,
  "message": "/usr/metron/0.5.1/bin/pcap_to_pdml.sh: line 19: tshark: command not found\n",
  "fullMessage": "RestException: /usr/metron/0.5.1/bin/pcap_to_pdml.sh: line 19: tshark: command not found\n"
}
  1. Install wireshark in full dev with yum -y install wireshark. This time PDML should be returned:
{
  "version": "0",
  "creator": "wireshark/1.8.10",
  "time": "Thu Jul 19 16:47:41 2018",
  "captureFile": "",
  "packets": [
    {
      "protos": [
        {
          "name": "geninfo",
          "pos": "0",
          "showname": "General information",
          "size": "130",
          "hide": null,
          "fields": [
            {
              "name": "num",
...
}
  1. Attempting to get PDML results for pages that don't exist (outside of the pageTotal) should return a 404.

I'm still working on adding some documentation to the script and endpoint. Otherwise this PR is ready for review. Expect another doc commit shortly.

Pull Request Checklist

Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines for complete smoke testing guides.

In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:

For all changes:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • Have you included steps or a guide to how the change may be verified and tested manually?

  • Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:

    mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via site-book/target/site/index.html:

    cd site-book
    mvn site
    

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.

mmiklavc and others added 30 commits June 26, 2018 23:48
Pcap job manager generics from cestella
…r for synchronicity. Kill remnants of the job service.
Get PcapTopologyIntegrationTest working
merrimanr and others added 15 commits July 17, 2018 14:52
# Conflicts:
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/MetronRestConstants.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/controller/PcapController.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/PcapService.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/PcapServiceImpl.java
#	metron-interface/metron-rest/src/main/resources/application.yml
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/PcapServiceImplTest.java
# Conflicts:
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/PcapServiceImplTest.java
# Conflicts:
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/PcapServiceImpl.java
<description>Interfaces for Metron</description>
<url>https://metron.apache.org/</url>
<properties>
<jackson.version>2.9.5</jackson.version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in both metron-rest and metron-rest-client. We are using several different jackson libraries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, do me a favor, when you test this out in full-dev, make sure that you can continue to use the REST endponts backing the management UI. We often have issues with classpath issues around newer versions of Jackson. Should we exclude the other jackson dependencies coming in transitively in metron-rest and metron-rest-client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the other endpoints and everything seems to still be functioning. I also inspected the mvn dependency tree and it looks like the jackson version is consistent across dependencies.

# See the License for the specific language governing permissions and
# limitations under the License.
#
tshark -i - -T pdml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure to add to the docs as part of this PR that we now rely on tshark being installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on that now.

@merrimanr
Copy link
Contributor Author

Latest commit documents wireshark dependency and gives instructions for possibly extending the pcap_to_pdml.sh script. I also updated the endpoint annotations.

@cestella
Copy link
Member

+1 by inspection, this looks good.

%dir %{metron_home}/lib
%{metron_home}/config/rest_application.yml
%{metron_home}/bin/metron-rest.sh
%{metron_home}/bin/pcap_to_pdml.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything to be done for the ubuntu debs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this by building the ubuntu debs with mvn clean package -Pbuild-debs. I did not encounter any issues.

@justinleet
Copy link
Contributor

Couple comments

  • For anyone running through this, they'll need to add a -u user:password to the curl commands.
  • More importantly, the status and PDML calls failed through Swagger. Taking Swagger's curl and copying it out (with the addition of the auth), worked perfectly fine. Didn't see anything come up in the logs, just got 404 with no response body.

Could you take a look into the Swagger issue and see if we can suss out what that might be? Assuming we can get that fixed (or at least diagnosed and ticketed if it's unrelated, so we can make sure to fix it before it goes into master), I'm good with this PR.

@justinleet
Copy link
Contributor

I checked in Safari, and the problem appears to be limited to just my Chrome and just those endpoints. @merrimanr if you've tried this in Chrome, I'm inclined to assume it's a problem with my machine and call this good to go.

@justinleet
Copy link
Contributor

After chatting with @merrimanr offline, I'm pretty sure it's my problem. It's not reproducible on his machine, and I can copy out chrome's actual request as a curl and run it with it working.

+1, thanks for the contribution.

…anel' into METRON-1638

# Conflicts:
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/controller/PcapController.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/PcapService.java
#	metron-interface/metron-rest/src/main/java/org/apache/metron/rest/service/impl/PcapServiceImpl.java
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/controller/PcapControllerIntegrationTest.java
#	metron-interface/metron-rest/src/test/java/org/apache/metron/rest/service/impl/PcapServiceImplTest.java
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants