Skip to content

Commit 96095cc

Browse files
committed
#410 - Review and fix alert docs
1 parent a78d753 commit 96095cc

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

docs/examples/alert.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Here's an example that demonstrates how to create the most simplistic alert poss
1818

1919
## An advanced alert
2020

21-
In the previous example we really kept things simple and only specified the required alert fields inline in the create method call.
21+
The previous example was as simple as it gets and only specified the required alert fields inline in the create method call.
2222
With a more advanced example this can become complicated and hard to read.
2323
Fortunately we can use `thehive4py`'s type hints to the rescue and specify more complex input alerts outside of the method call.
2424

@@ -37,11 +37,13 @@ Finally after the creation of the alert we saved the response in the `output_ale
3737

3838
## Alert observables
3939

40-
TheHive API provides multiple ways to add observables to alerts, let them be textual or file based observables.
40+
In TheHive an observable is a piece of data or evidence (e.g., an IP address, domain, etc.) associated with a security incident, used to provide context and aid in the investigation and response process.
41+
42+
Let's take a look at different ways of populating alerts with observables, let them be textual or file based observables.
4143

4244
### Add observables during alert creation
4345

44-
We can add observables already during alert creation. This is a great way to combine alert and observable creation in a simple and atomic way:
46+
We can add observables already during alert creation. This is a great way to combine alert and observable creation in an atomic way:
4547

4648
Let's create an alert with an `ip` and a `domain` observable:
4749

@@ -51,7 +53,7 @@ Let's create an alert with an `ip` and a `domain` observable:
5153

5254
### Add observables to an existing alert
5355

54-
While it's probably the most convenient way to combine alert and observable creation in a single call, sometimes we don't have all the observables at hand during alert creation time.
56+
While it's probably the most convenient way to combine alert and observable creation in a single call, sometimes we don't have all the observables at hand during alert creation time or we have such a large number of observables that we cannot send them all in one single request.
5557

5658
Fortunately TheHive API supports alert observable creation on already existing alerts. Let's repeat the previous example, but this time add the two observables to an existing alert using the [alert.create_observable][thehive4py.endpoints.alert.AlertEndpoint.create_observable] method:
5759

@@ -62,7 +64,7 @@ Fortunately TheHive API supports alert observable creation on already existing a
6264

6365
### Add file based observables
6466

65-
In the previous examples we've seen how to handle simple observables without attachments. Next we will create a temporary directory with a dummy file and some dummy content that will represent our file based observable and add it to an alert:
67+
In the previous examples we've seen how to handle observables without attachments. However sometimes we also want to add attachments to an observable not only textual data. Fortunately that is supported by TheHive. So in the next example let's create a temporary directory with a dummy file and some dummy content that will represent our file based observable and add it to an alert:
6668

6769

6870
```python
@@ -77,21 +79,21 @@ In our example `attachment_key` is used to specify the relationship between the
7779

7880
## Update single and bulk
7981

80-
Sometimes an existing alert needs to be updated. `thehive4py` offers multiple ways to accomplish this task either with a single alert or multiple ones.
82+
Creating alerts is fun but sometimes an existing alert also needs to be updated. As expected `thehive4py` offers multiple ways to accomplish this task either on a single alert or multiple ones.
8183

8284
### Update single
8385

84-
A single alert can be updated using [alert.update][thehive4py.endpoints.alert.AlertEndpoint.update] method. The method requires the `alert_id` of the alert to be updated and the `fields` to update.
86+
A single alert can be updated using the [alert.update][thehive4py.endpoints.alert.AlertEndpoint.update] method. The method requires the `alert_id` of the alert to be updated and the `fields` to update.
8587

8688
```python
8789
--8<-- "examples/alert/update_single.py"
8890
```
8991

9092
In the above example we've updated the `title` and the `tags` fields.
9193

92-
Be mindful though, `thehive4py` is a lightweight wrapper around TheHive API and offers no object relationship mapping functionalities, meaning that the original `original_alert` won't reflect the changes of the update.
94+
Be mindful though, `thehive4py` is a lightweight wrapper around TheHive API and offers no object relationship mapping functionalities, meaning that the `original_alert` won't reflect the changes of the update.
9395

94-
To work with the updated alert we fetched the latest version using the [alert.get][thehive4py.endpoints.alert.AlertEndpoint.get] method and stored it in the `updated_alert` variable.
96+
In order to work with the updated alert we had to fetch the latest version using the [alert.get][thehive4py.endpoints.alert.AlertEndpoint.get] method and store it in the `updated_alert` variable.
9597

9698
Now the content of `updated_alert` should reflect the changes we made with our update request.
9799

@@ -100,8 +102,8 @@ Now the content of `updated_alert` should reflect the changes we made with our u
100102

101103
### Update bulk
102104

103-
To update the **same fields** with the **same values** on multiple alerts at the same time, one can use [alert.bulk_update][thehive4py.endpoints.alert.AlertEndpoint.bulk_update] method.
104-
The method accepts the same `fields` dictionary with an additional `ids` field on it, which should contain the list of ids of the alerts to be bulk updated.
105+
It is also possible to update many alerts at the same time, however there's a constraint: the content of the `fields` property will be applied to all the specified alerts uniformly. With all that said one can use [alert.bulk_update][thehive4py.endpoints.alert.AlertEndpoint.bulk_update] method for bulk updates.
106+
The method accepts the same `fields` dictionary as before but with an additional `ids` field on it, which should contain the list of ids of the alerts to be bulk updated.
105107

106108
```python
107109
--8<-- "examples/alert/update_bulk.py"
@@ -112,7 +114,7 @@ Then we update the fields `title` and `tags` on both alerts using the bulk updat
112114

113115
## Get and find
114116

115-
There are multiple ways to retrieve already existing alerts:
117+
There are multiple ways to retrieve already existing alerts, we can fetch them one by one or many at once!
116118

117119
### Get a single alert
118120

@@ -128,7 +130,7 @@ To fetch multiple alerts based on arbitrary conditions one can use the [alert.fi
128130

129131
In the next example we will create two alerts with different tags. The first alert will get the `antivirus` tag while the second one will get the `phishing` tag.
130132

131-
Then we will construct a query filter that will look for alerts with these tags on them:
133+
Then we will construct query filters in different ways to look for alerts with these tags on them:
132134

133135
```python
134136
--8<-- "examples/alert/fetch_with_find.py"
@@ -175,7 +177,7 @@ Oftentimes new alerts correspond to an already existing case. Fortunately we hav
175177
--8<-- "examples/alert/case_merge.py"
176178
```
177179

178-
In the above example we prepared a `parent_case` to which we merge the `new_alert` using their ids and finally save the updated case in the `updated_parent_case` variable.
180+
In the above example we prepared a `parent_case` to which we merge the `new_alert` using its id and finally save the updated case in the `updated_parent_case` variable.
179181

180182
!!! tip
181183
It can happen that multiple new alerts belong to the same parent case. In such situation we can use the [alert.bulk_merge_into_case][thehive4py.endpoints.alert.AlertEndpoint.bulk_merge_into_case] method for a more convenient merge process.
@@ -205,4 +207,4 @@ To delete multiple alerts via a single request one can use the [alert.bulk_delet
205207
--8<-- "examples/alert/delete_bulk.py"
206208
```
207209

208-
In the above example we created two alerts and saved their ids in the `alert_ids_to_delete` variable just to pass it in the bulk deletion method.
210+
In the above example we created two alerts and saved their ids in the `alert_ids_to_delete` variable just to pass it to the bulk deletion method.

examples/alert/fetch_with_find.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
raw_filters = {
3232
"_or": [
3333
{"_eq": {"_field": "tags", "_value": "antivirus"}},
34-
{"_eq": {"_field": "tags", "_value": "antivirus"}},
34+
{"_eq": {"_field": "tags", "_value": "phishing"}},
3535
]
3636
}
3737
all_alerts_with_raw_filters = hive.alert.find(filters=raw_filters)

examples/alert/observable_from_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
with tempfile.TemporaryDirectory() as tmpdir:
1111

1212
observable_filepath = os.path.join(tmpdir, "my-observable.txt")
13-
with open(observable_filepath) as observable_file:
13+
with open(observable_filepath, "w") as observable_file:
1414
observable_file.write("some observable content")
1515

1616
attachment_key = uuid.uuid4().hex

thehive4py/endpoints/alert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def create_observable(
174174
def add_attachment(
175175
self, alert_id: str, attachment_paths: List[str]
176176
) -> List[OutputAttachment]:
177-
"""Create an observable in an alert.
177+
"""Create an attachment in an alert.
178178
179179
Args:
180180
alert_id: The id of the alert.
@@ -313,7 +313,7 @@ def find_observables(
313313
sortby: Optional[SortExpr] = None,
314314
paginate: Optional[Paginate] = None,
315315
) -> List[OutputObservable]:
316-
"""Find observable related to an alert.
316+
"""Find observables related to an alert.
317317
318318
Args:
319319
alert_id: The id of the alert.

0 commit comments

Comments
 (0)