Created
May 7, 2015 17:16
-
-
Save deckerego/3e00f9295a88aa38abf6 to your computer and use it in GitHub Desktop.
Send your current IP address to Slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
config_values = { | |
'slack_api_token': 'toooooken', | |
'slack_channel': '#channel' | |
} | |
class Configuration(object): | |
def __init__(self): | |
parser = argparse.ArgumentParser() | |
args, _ = parser.parse_known_args() | |
def get(self, name): | |
return config_values.get(name) | |
configuration = Configuration() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import socket | |
from slacker import Slacker | |
from config import configuration | |
logger = logging.getLogger('slack') | |
class Slack(object): | |
def __init__(self, printer): | |
self.slack = Slacker(configuration.get('slack_api_token')) | |
self.channel = configuration.get('slack_channel') | |
def sendAddr(self, message): | |
test_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
test_sock.connect(("8.8.8.8", 53)) | |
self.hostname = test_sock.getsockname()[0] | |
self.slack.chat.post_message(self.channel, "Current Host: %s" % self.hostname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment