Functions
datetime_compare
Overview
Development
Deployment
- Configuration
- Authentication
- Provision
- Secret Manager
- Docker
- Kubernetes
- AWS ECS
- Specifications
Providers
- Overview
- Fingerprints
- Adding a New Provider
- Getting Started
- What is a Provider?
- Supported Providers
Workflows
Keep API
- GETRoot
- providers
- actions
- healthcheck
- topology
- alerts
- deduplications
- maintenance
- incidents
- settings
- workflows
- whoami
- pusher
- status
- rules
- preset
- enrichment
- auth
- metrics
- users
- groups
- mappings
- dashboard
- tags
Keep CLI
Functions
datetime_compare
datetime_compare(t1, t2) compares t1-t2 and returns the diff in seconds
Input
datetime.datetime, datetime.datetime
Output
Integer, timedelta in seconds.
Example
actions:
- name: trigger-slack
condition:
- type: threshold
value: keep.datetime_compare(keep.utcnow(), keep.to_utc("{{ steps.this.results[0][0] }}"))
compare_to: 3600 # seconds (1 hour)
compare_type: gt # greater than
from datetime import datetime
def datetime_compare(t1: datetime, t2: datetime) -> int:
"""
Compares two datetime objects and returns the time difference in seconds.
:param t1: First datetime object
:param t2: Second datetime object
:return: Time difference in seconds
"""
return int((t1 - t2).total_seconds())
# Example usage:
# t1 = datetime.utcnow()
# t2 = datetime.utcnow() - timedelta(hours=2)
# print(datetime_compare(t1, t2)) # Should return 7200 (2 hours * 3600 seconds)