Skip to content

Commit

Permalink
#1113 update program and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed Oct 11, 2022
1 parent aee3b8f commit af182db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
14 changes: 8 additions & 6 deletions docs/admin_guides/manage-private-custom-analyzers-responders.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This guide propose a way to manage your own analyzers without publishing them or

Make Cortex know of custom Analyzers and Responders.

Update the `/etc/cortex/application.conf` or ensure your configuration is similar to:
Update the `/etc/cortex/application.conf` or add the folders where you store your custom code. Ensure your configuration is similar to:

```yaml
[..]
Expand Down Expand Up @@ -38,7 +38,7 @@ See:
* [How to create an Analyzer guide](../dev_guides/how-to-create-an-analyzer.md)
* [Analyzer definition file](../dev_guides/analyzers_definition.md)

To prepare your package you have to write your `Dockerfile`. We recommend starting with [this one](https://github.com/TheHive-Project/Cortex-Analyzers/blob/master/utils/docker/Dockerfile_template) and update it, especially if additional programs on the system are required (the list could be added in a `programs.txt` file).
To prepare your package you have to write your `Dockerfile`. We recommend starting with [this one](https://github.com/TheHive-Project/Cortex-Analyzers/blob/master/utils/docker/Dockerfile_template) and update it, especially if additional packages or programs are required in the image.

As a result, your program should be at least:

Expand All @@ -47,7 +47,6 @@ Analyzer/
├── analyzer.json #required
├── analyzer.py #required
├── README.md #optional
├── programs.txt #optional
├── Dockerfile #required
└── requirements.txt #required
```
Expand All @@ -72,6 +71,8 @@ analyzerspath="/opt/customneurons/analyzers"
responderspath="/opt/customneurons/responders"
# Set path to your docker images archives
dockerimagearchives="/opt/backup-images"
# Set a name for the docker image registry
dockerimageregistryname="localhost"
# Set a name for the docker image repository
dockerimagerepositoryname="customimage"
```
Expand All @@ -81,19 +82,20 @@ dockerimagerepositoryname="customimage"
* `analyzerspath`, the path to your custom analyzers repository (it should be the same as in the Cortex configuration)
* `responderspath`, the path to your custom responders repository (it should be the same as in the Cortex configuration)
* `dockerimagearchives`, the path to your docker images archives. Indeed, once built, the program save the docker images in a dedicated folder
* `dockerimageregistryname`, name for the docker image registry. By default this is localhost. Even if you do not have a docker registry, Cortex will ensure to use the local images loaded.
* `dockerimagerepositoryname`, a name for the docker image repository, used in docker image names or tags. `customimage` is used by default

Once updated, save the file.

#### Run the program
#### Install requirements

Before running it, there are few requirements:

* `jq` (from [https://stedolan.github.io/jq/](https://stedolan.github.io/jq/)) should be installed in the system. For example, if using Ubuntu or Debian, run the following command: `apt install jq`
* _Python3 + json lib_ should be available on the system
* the Python library `json-spec` should be installed (`pip3 install json-spec`)

#### Build your image
#### Run and build your image

The program has several options.

Expand All @@ -113,7 +115,7 @@ To run it successfully, you need to identify the type of neuron to build, `analy
For example:

```bash
./build-customimage.sh -t analyzer -b /home/jerome/Devel/PrivateAnalyzer/analyzer.json
./build-customimage.sh -t analyzer -b /home/dev/PrivateAnalyzer/analyzer.json
```

This will:
Expand Down
21 changes: 4 additions & 17 deletions utils/docker/build-customimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ analyzerspath="/opt/customneurons/analyzers"
responderspath="/opt/customneurons/responders"
# Set the path to your docker images archives
dockerimagearchives="/opt/backup-images"
# Set a name for the docker image registry
dockerimageregistryname="localhost"
# Set a name for the docker image repository
dockerimagerepositoryname="customimage"
dockerimagerepositoryname="customimages"

###################################
# HOW TO RELOAD DOCKERIMAGES #
Expand Down Expand Up @@ -378,24 +380,9 @@ build-image() {
exit
fi
# Set docker image name
dockerimagename="${dockerimagerepositoryname}/${neuronname}:latest"
dockerimagename="${dockerimageregistryname}/${dockerimagerepositoryname}/${neuronname}:latest"
# Set docker image archive name
archivename="${dockerimagearchives}/${dockerimagerepositoryname}-${neuronname}.tar"
# Check if programs.txt exists
if [ -f "${folderpath}/programs.txt" ]
then
log ok "Additionnal programs required. Read the file programs.txt and ensure having provided a custom Dockerfile in ${folderpath}"
if [ ! -f "${folderpath}/Dockerfile" ]
then
log ko "Custom Dockerfile not found in ${folderpath}. Edit a Dockerfile with required packages to install. See ${folderpath}/programs.txt"
exit 1
fi
else
log ok "No additionnal programs required (programs.txt not found)"
fi

workername=$(dirname ${jsonpath} | awk -F "/" ' {print $NF} ')
command=$(cat ${jsonpath} | jq '.command')

# if no Dockerfile, create a default one
(
Expand Down

0 comments on commit af182db

Please sign in to comment.