70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
import paramiko
|
|
import yaml
|
|
|
|
def main():
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect('140.44.4.41', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
|
|
|
cm_manifest = """
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: argocd-notifications-cm
|
|
namespace: infrastructure
|
|
labels:
|
|
app.kubernetes.io/component: notifications-controller
|
|
app.kubernetes.io/instance: argocd
|
|
app.kubernetes.io/name: argocd-notifications-controller
|
|
app.kubernetes.io/part-of: argocd
|
|
data:
|
|
context: |
|
|
argocdUrl: https://argo.snarfnet.net
|
|
service.webhook.gotify: |
|
|
url: http://140.44.4.70:8090/message?token=A8aWxGiToPsAuToMaTiO
|
|
headers:
|
|
- name: Content-Type
|
|
value: application/json
|
|
template.app-sync-status: |
|
|
webhook:
|
|
gotify:
|
|
method: POST
|
|
body: |
|
|
{
|
|
"title": "ArgoCD: {{.app.metadata.name}} ({{.app.status.sync.status}})",
|
|
"message": "Application: {{.app.metadata.name}}\\nCluster: {{.app.spec.destination.server}}\\nSync Status: {{.app.status.sync.status}}\\nHealth: {{.app.status.health.status}}\\nURL: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
|
|
"priority": 4
|
|
}
|
|
template.app-health-degraded: |
|
|
webhook:
|
|
gotify:
|
|
method: POST
|
|
body: |
|
|
{
|
|
"title": "ArgoCD: {{.app.metadata.name}} Health DEGRADED",
|
|
"message": "Application: {{.app.metadata.name}}\\nCluster: {{.app.spec.destination.server}}\\nHealth: {{.app.status.health.status}}\\nURL: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
|
|
"priority": 8
|
|
}
|
|
trigger.on-sync-failed: |
|
|
- description: Application syncing has failed
|
|
send: [app-sync-status]
|
|
when: app.status.operationState != nil and app.status.operationState.phase in ['Error', 'Failed']
|
|
trigger.on-health-degraded: |
|
|
- description: Application health is degraded
|
|
send: [app-health-degraded]
|
|
when: app.status.health.status == 'Degraded'
|
|
"""
|
|
stdin, stdout, stderr = ssh.exec_command("kubectl apply -f -")
|
|
stdin.write(cm_manifest)
|
|
stdin.channel.shutdown_write()
|
|
print("CM Apply stdout:\n", stdout.read().decode())
|
|
print("CM Apply stderr:\n", stderr.read().decode())
|
|
|
|
stdin, stdout, stderr = ssh.exec_command("kubectl rollout restart deployment/argocd-notifications-controller -n infrastructure")
|
|
print("Rollout restart:\n", stdout.read().decode())
|
|
|
|
ssh.close()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|