diff --git a/docs/playbook-reference/actions/change-tracking.rst b/docs/playbook-reference/actions/change-tracking.rst index ac8c90fe6..e3b7c6579 100644 --- a/docs/playbook-reference/actions/change-tracking.rst +++ b/docs/playbook-reference/actions/change-tracking.rst @@ -12,4 +12,6 @@ These actions were built for tracking changes in your cluster .. robusta-action:: playbooks.robusta_playbooks.babysitter.resource_babysitter on_deployment_update +.. robusta-action:: playbooks.robusta_playbooks.babysitter.json_change_tracker on_deployment_update + diff --git a/docs/playbook-reference/kubernetes-examples/playbook-track-changes.rst b/docs/playbook-reference/kubernetes-examples/playbook-track-changes.rst index d5deab0b1..e670f215c 100644 --- a/docs/playbook-reference/kubernetes-examples/playbook-track-changes.rst +++ b/docs/playbook-reference/kubernetes-examples/playbook-track-changes.rst @@ -141,6 +141,43 @@ A Robusta notification will arrive in your configured :ref:`sinks `. + +**Testing**: + +Modify a Deployment image in your cluster. + +A notification with the Deployment manifest, as json, should be sent to the webhook url + + + Cleanup ------------------------------ Remove the playbook you added based on your specific use case from the ``customPlaybooks`` in your ``generated_values.yaml`` file. Then, perform a :ref:`Helm Upgrade `. diff --git a/playbooks/robusta_playbooks/babysitter.py b/playbooks/robusta_playbooks/babysitter.py index bc25908e7..8f9f694fc 100644 --- a/playbooks/robusta_playbooks/babysitter.py +++ b/playbooks/robusta_playbooks/babysitter.py @@ -4,8 +4,11 @@ # * https://github.com/google/diff-match-patch/wiki/Language:-Python (see output format here: https://neil.fraser.name/software/diff_match_patch/demos/diff.html) # * https://github.com/wagoodman/diff2HtmlCompare # * https://github.com/GerHobbelt/google-diff-match-patch +import json import logging -from typing import List +from typing import List, Optional, Dict + +import requests from robusta.api import ( ActionParams, @@ -79,3 +82,27 @@ def resource_babysitter(event: KubernetesAnyChangeEvent, config: BabysitterConfi title="Kubernetes Manifest Change", ) event.add_finding(finding) + + +class UrlParam(ActionParams): + """ + :var url: url that should be used in the action + """ + + url: str + headers: Optional[Dict[str, str]] = None + + +@action +def json_change_tracker(event: KubernetesAnyChangeEvent, params: UrlParam): + """ + post change json to the specified url + this action doesn't create a finding + """ + try: + event_dict = event.obj.to_dict() + event_dict["operation"] = event.operation.value + event_json = json.dumps(event_dict, indent=2) + requests.post(params.url, headers=params.headers, data=event_json) + except Exception as e: + logging.exception(f"Failed to post change event to {params.url}. event: {event_json}") \ No newline at end of file