github.com/argoproj/argo-events@v1.9.1/docs/sensors/filters/ctx.md (about) 1 2 # Context Filter 3 4 Context filter is applied to the event context. A CloudEvent from Webhook event-source has payload structure as: 5 6 ```json 7 { 8 "context": { 9 "type": "type_of_event_source", 10 "specversion": "cloud_events_version", 11 "source": "name_of_the_event_source", 12 "id": "unique_event_id", 13 "time": "event_time", 14 "datacontenttype": "type_of_data", 15 "subject": "name_of_the_configuration_within_event_source" 16 }, 17 "data": { 18 "header": {}, 19 "body": {}, 20 } 21 } 22 ``` 23 24 ## Fields 25 26 Context filter has following fields: 27 28 ```yaml 29 filters: 30 context: 31 type: event_type 32 subject: event_subject 33 source: event_source 34 datacontenttype: event_data_content_type 35 ``` 36 37 You can also specify id, specversion and time fields in the YAML manifest, but they are ignored in filtering. 38 39 **Note** It could be useless to build a context filter based on `datacontenttype`, `source` and `subject` as currently they come fixed from event-source: 40 41 - `datacontenttype` is always `application/json` 42 - `source` corresponds to `eventSourceName` specified in the Sensor YAML manifest 43 - `subject` corresponds to `eventName` specified in the Sensor YAML manifest 44 45 ## How it works 46 47 Specify one or more of the available context fields: 48 49 ```yaml 50 apiVersion: argoproj.io/v1alpha1 51 kind: Sensor 52 metadata: 53 name: with-ctx-filter 54 spec: 55 template: 56 serviceAccountName: operate-workflow-sa 57 dependencies: 58 - name: test-dep 59 eventSourceName: webhook 60 eventName: example 61 filters: 62 context: 63 source: custom-webhook 64 ``` 65 66 ## Practical example 67 68 1. Create a webhook event-source 69 70 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml 71 72 1. Create a webhook sensor with context filter 73 74 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/filter-with-context.yaml 75 76 1. Send an HTTP request to event-source 77 78 curl -d '{"message":"this is my first webhook"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example 79 80 1. You will notice in sensor logs that the event is invalid as the sensor expects `custom-webhook` as the value of the `source` 81 82 ## Further examples 83 84 You can find some examples [here](https://github.com/argoproj/argo-events/tree/master/examples/sensors).