Skip to content

Commit

Permalink
Fixing slack webhook url
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFarley committed Jan 15, 2022
1 parent d9021af commit 6c30f2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import os
import time
from helpers import INTERVAL_TIME, PROMETHEUS_URL, DRY_RUN, VERBOSE, SLACK_WEBHOOK_URL
from helpers import INTERVAL_TIME, PROMETHEUS_URL, DRY_RUN, VERBOSE
from helpers import convert_bytes_to_storage, scale_up_pvc, testIfPrometheusIsAccessible, describe_all_pvcs
from helpers import fetch_pvcs_from_prometheus, printHeaderAndConfiguration, calculateBytesToScaleTo
import slack
Expand Down Expand Up @@ -55,7 +55,7 @@

# Precursor check to ensure we have info for this pvc in kubernetes object
if volume_description not in pvcs_in_kubernetes:
print(" ERROR: The volume {} was not found in Kubernetes but had metrics in Prometheus. This may be an old volume, was just deleted, or some random jitter is occurring. If this continues to occur, please report an bug. You might also be using an older version of Prometheus, please make sure you're using v2.30.0 or newer before reporting a bug for this.".format(volume_description))
print("ERROR: The volume {} was not found in Kubernetes but had metrics in Prometheus. This may be an old volume, was just deleted, or some random jitter is occurring. If this continues to occur, please report an bug. You might also be using an older version of Prometheus, please make sure you're using v2.30.0 or newer before reporting a bug for this.".format(volume_description))
continue

if VERBOSE:
Expand Down Expand Up @@ -142,7 +142,7 @@
IN_MEMORY_STORAGE[volume_description] * INTERVAL_TIME
)
print(status_output)
if SLACK_WEBHOOK_URL and len(SLACK_WEBHOOK_URL) > 0:
if slack.SLACK_WEBHOOK_URL and len(slack.SLACK_WEBHOOK_URL) > 0:
slack.send(status_output)
else:
status_output = "FAILED Scaling up `{}` by `{}%` from `{}` to `{}`, it was using more than `{}%` disk space over the last `{} seconds`".format(
Expand Down
14 changes: 7 additions & 7 deletions slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def getEmojiFromSeverity(severity):
else: return ':white_check_mark:';

# Default webhook (paste yours here if you want to not have to provide it on the CLI)
slack_webhook_url = os.getenv('SLACK_WEBHOOK_URL', "")
slack_channel = os.getenv('SLACK_CHANNEL', "devops")
SLACK_WEBHOOK_URL = os.getenv('SLACK_WEBHOOK_URL', "")
SLACK_CHANNEL = os.getenv('SLACK_CHANNEL', "devops")

# Usage and CLI opts handling
usage = ' \n\
Expand All @@ -49,10 +49,10 @@ def getEmojiFromSeverity(severity):
'


def send(body, username="Kubernetes Volume Autoscaler", severity="info", channel=slack_channel, emoji="", iconurl="https://raw.githubusercontent.com/DevOps-Nirvana/Kubernetes-Volume-Autoscaler/master/icon.png", verbose=False):
def send(body, username="Kubernetes Volume Autoscaler", severity="info", channel=SLACK_CHANNEL, emoji="", iconurl="https://raw.githubusercontent.com/DevOps-Nirvana/Kubernetes-Volume-Autoscaler/master/icon.png", verbose=False):

# Skip if not set
if not slack_webhook_url or len(slack_webhook_url) == 0:
# Skip if not set or set invalidly
if not SLACK_WEBHOOK_URL or len(SLACK_WEBHOOK_URL) == 0 or SLACK_WEBHOOK_URL == "REPLACEME":
print("Slack webhook URL not set, skipping")
return False

Expand Down Expand Up @@ -80,8 +80,8 @@ def send(body, username="Kubernetes Volume Autoscaler", severity="info", channel
# Send the request to Slack
try:
rawpayload = json.dumps(payload).encode('utf-8')
if verbose: print("VERBOSE: Sending request to " + slack_webhook_url + "...")
request = urllib.request.Request(slack_webhook_url, rawpayload, {'Content-Type': 'application/json', 'Content-Length': len(rawpayload)})
if verbose: print("VERBOSE: Sending request to " + SLACK_WEBHOOK_URL + "...")
request = urllib.request.Request(SLACK_WEBHOOK_URL, rawpayload, {'Content-Type': 'application/json', 'Content-Length': len(rawpayload)})
response = urllib.request.urlopen(request)
result = response.read()
result = str(result)
Expand Down

0 comments on commit 6c30f2a

Please sign in to comment.