def post_msg(diff_data):
    """
    Post Diff found in run config to Webex Teams
    """
    print("Posting msgs")
    md = "**Base Configuration Change Detected** \n"
    teams.post_markdown(bot_token, roomId, md)
    teams.post_message(bot_token, roomId, diff_data)
Esempio n. 2
0
def do_something(resp):
    trig = resp['text'].split()
    log.info(trig[0])
    if trig[0].lower() in ['webhook', 'webhooks', 'hook', 'hooks']:
        do_spark(resp)
    elif trig[0].lower() == 'meraki':
        do_meraki(resp)
    else:
        Spark.post_message(accessToken, resp['roomId'], resp['text'])  # echo
Esempio n. 3
0
#Example searches rooms for "pyCiscoSpark TestRoom1", finds the id, and then posts a test message "python test message1"

import pyCiscoSpark
import sys


def search (values, searchFor):
    for k in values["items"]:
        print k["title"]
        if (k["title"] == searchFor) : return k["id"]
    return None

accesstoken="Bearer "+str(sys.argv[1])

rooms_dict=pyCiscoSpark.get_rooms(accesstoken)

roomid = search (rooms_dict, "Test3 Room")

print roomid

resp_dict = pyCiscoSpark.post_message(accesstoken,roomid,"A different test message")

print resp_dict


Esempio n. 4
0
import pyCiscoSpark as Spark
import pprint

auth = 'INSERT AUTH HERE'
roomId = 'Y2lzY29zcGFyazovL3VzL1JPT00vNTZmOGM4ZjAtMTI4Ny0xMWU4LWI2MzYtYjcwOGNjMzRmMzE4'
pp = pprint.PrettyPrinter(indent=4)

resp = Spark.post_message(auth, roomId, "Hello World")
pp.pprint(resp)
Esempio n. 5
0
#!/usr/bin/python
import pyCiscoSpark
import sys
import config
import os

path = os.path.abspath(os.curdir)
log = path + "/TXT/spark_send_message_log.txt"
message = path + "/TXT/spark_send_message.txt"

print log
print message

#storing the Authentication token and roomdID for Video BOT
accesstoken = config.spark_accesstoken
roomid = config.spark_roomid

f = open(log, "a")
g = open(message, "r")

newmessage = g.read()

f.write("\n")
f.write(newmessage)

pyCiscoSpark.post_message(accesstoken, roomid, newmessage)
Esempio n. 6
0
#Example searches rooms for "Test Room", finds the id, and then posts a test message "python test message1"

import pyCiscoSpark
import sys


def search(values, searchFor):
    for k in values["items"]:
        print(k["title"])
        if (k["title"] == searchFor): return k["id"]
    return None


accesstoken = "Bearer " + str(sys.argv[1])

rooms_dict = pyCiscoSpark.get_rooms(accesstoken)

roomid = search(rooms_dict, "Test Room")

print(roomid)

resp_dict = pyCiscoSpark.post_message(accesstoken, roomid,
                                      "A different test message")

print(resp_dict)
Esempio n. 7
0
def dutyAlert():
  wEvent('dutyAlert','START',str('Start Alert duty process'))
  roomname = api.config['APP_SPACE_NAME']
  status = 'OK'

  # Create Spark room instead if DUTY ALERT ROOM ID is recorded in the user profil
  if session['roomid']:
    # Get Duty room
    try:
      room = get_room(session['accesstoken'],session['roomid'])
      wEvent('dutyAlert','getroom',str(session['roomid'] + " Duty room getting"))
    except Exception as e:
      wEvent('dutyAlert','getroom',str(session['roomid'] + " Issue during room getting"))
      return 'KO'
  else:
    # Duty room creation
    try:
      room = post_room(session['accesstoken'],roomname)
      wEvent('dutyAlert','setroom',str(room['id'] + " Duty room creation"))
    except Exception as e:
      wEvent('dutyAlert','setroom',str("Issue during room creation (name:"+roomname+")"))
      return 'KO'

  # Prepare message
  roomlink = re.split('ciscospark://us/ROOM/', str(base64.b64decode(room['id'])))
  roommsg  = api.config['APP_SPACE_MSG']
  roommsg += '* Space name: ' + roomname + '\n'
  roommsg += '* Space id: ' + room['id'] + '\n'
  roommsg += '* Space web url: ' + 'https://web.ciscospark.com/#/rooms/' + str(roomlink[1]) + '\n'
  roommsg += '* Space web url for login: '******'https://web.ciscospark.com/#/launch/rooms/' + str(roomlink[1]) '\n'
  roommsg += '* Space app url: ' + 'spark://rooms/' + str(roomlink[1]) +'\n'
  roommsg += '* Duty login: '******'login'] + '\n'
  roommsg += '* Duty mobile: ' + session['mobile'] + '\n'
  roommsg += '* Duty mail: ' + session['email']
  wEvent('dutyAlert','roommsg',room['id'] + ' ' + str(roommsg))

  # Add user room membership instead if DUTY TEAM ID is recorded in the user profil
  if session['teamid']:
    # Add team in the duty room
    try:
      membership = post_roommembership(session['accesstoken'],room['id'],session['teamid'],'true')
      wEvent('dutyAlert','team membership',str(room['id'] + " Duty team room membership " + session['teamid']))
    except Exception as e:
      status = 'KO'
      wEvent('dutyAlert','team membership',str(room['id'] + " Issue during team room membership " + session['teamid']))

  else:
    # Add user in the duty room
    try:
      membership = post_roommembership(session['accesstoken'],room['id'],session['email'],'true')
      wEvent('dutyAlert','user membership',str(room['id'] + " Duty room membership " + session['email']))
    except Exception as e:
      status = 'KO'
      wEvent('dutyAlert','user membership',str(room['id'] + " Issue during room membership " + session['email']))

  # Duty room message post
  try:
    msg = post_message(session['accesstoken'],room['id'],roommsg)
    wEvent('dutyAlert','message',str(room['id'] + " Duty room message post"))
  except Exception as e:
    status = 'KO'
    wEvent('dutyAlert','message',str(room['id'] + " Issue during post message"))

  # Duty sms processing
  try:
    sms(session['mobile'],roommsg)
    wEvent('dutyAlert','sms',str(room['id'] + " Duty sms processing"))
  except Exception as e:
    wEvent('dutyAlert','sms',str(room['id'] + " Issue during sms processing"))

  # Duty call processing
  try:
    call(session['mobile'],'http://www.tropo.com/docs/troporocks.mp3')
    wEvent('dutyAlert','call',str(room['id'] + " Duty call processing"))
  except Exception as e:
    wEvent('dutyAlert','call',str(room['id'] + " Issue during call processing"))

  # Duty send email
  try:
    resMail = sendMail(api.config['APP_MAIL_HOST'],api.config['APP_MAIL'],session['email'],roommsg)
    wEvent('dutyAlert','email',str(room['id'] + " Duty email processing"))
  except Exception as e:
    wEvent('dutyAlert','email',str(room['id'] + " Issue during email processing"))

  # End of Duty Alert auto treatment
  wEvent('dutyAlert','END',str(room['id'] + " Duty Alert created, status: " + status))
  return str("Duty call alert done, status "+status)
Esempio n. 8
0
def newSub():
    error = None

    # Get POST param
    title = str(request.form['title'])
    if not title:
        wEvent('newSub', session['uid'], 'Thanks to provide title', 'KO')
        return 'Thanks to provide title'

    description = str(request.form['description'])
    if not description:
        wEvent('newSub', session['uid'], 'Thanks to provide description', 'KO')
        return 'Thanks to provide description'

    severity = str(request.form['severity'])
    if not severity:
        wEvent('newSub', session['uid'], 'Thanks to provide severity', 'KO')
        return 'Thanks to provide severity'

    # Create Space
    try:
        space = pyCiscoSpark.post_room(api.config['ACCESS_TOKEN'], title)
        session['sid'] = space['id']
        session['sname'] = title
        sEvent('creation')
        wEvent('newSub', session['uid'], "Space created, id: " + space['id'],
               'OK')
    except Exception as e:
        wEvent('newSub', session['uid'],
               "Issue during space creation, name: " + title, 'KO')
        return "Issue during space creation"

    # Create webhook
    try:
        webhookmsg = pyCiscoSpark.post_webhook(
            api.config['ACCESS_TOKEN'], title,
            api.config['SPARK_WEBHOOK'] + '/message', 'messages', 'all',
            str('roomId=' + space['id']))
        exeReq("INSERT INTO spaces VALUES ('" + space['id'] + "','1','" +
               webhookmsg['id'] + "','open', '', CURDATE(), NOW());")
        wEvent('newSub', session['uid'],
               "Webhook created, space id: " + space['id'], 'OK')
    except Exception as e:
        wEvent('newSub', session['uid'],
               "Issue during webhook space creation, name: " + title, 'KO')
        return "Issue during webhook space creation"

    # Get members from DB and associat to the Space (remote+local)
    try:
        member_list = exeReq(
            "SELECT DISTINCT email,uid,login,admin FROM users WHERE grp = 'EXP' OR grp = 'FR' OR grp = 'AL';"
        )
    except Exception as e:
        wEvent('newSub', session['uid'],
               'Database error (get member_list data)', 'KO')
        return 'Database error (get member_list data)'
    for user in member_list:
        try:
            pyCiscoSpark.post_roommembership(api.config['ACCESS_TOKEN'],
                                             space['id'], user[0], user[3])
            exeReq("INSERT INTO spaces VALUES ('" + space['id'] + "','" +
                   str(user[1]) + "','" + title + "','open', '" + severity +
                   "', CURDATE(), NOW());")
            sEvent('Membership added:' + user[0])
            wEvent('newSub', session['uid'],
                   "User " + user[0] + " add to the space " + title, 'OK')
        except Exception as e:
            wEvent('newSub', session['uid'],
                   "Issue when add user " + user[0] + " to the space " + title,
                   'KO')

    # Post TechRequest initial messages in the Space
    msg = 'Welcome in the new TechRequest Space'
    msg += '\n- Title: ' + title
    msg += '\n- Description: ' + description
    msg += '\n- Severity: ' + severity
    msg += '\n- Requestor: ' + session['login']
    msg += '\n- Requestor email: ' + session['email']
    msg += '\n- Webserver: ' + api.config['SPARK_WEBHOOK']
    msg += '\n- Space ID: ' + session['sid']
    msg += '\nRemember that you can use the following bot in 1:1 space for additionnal support'
    msg += '\n- TechRequest.io : specific support for TechRequest'
    msg += '\n- [email protected] : additionnal tool like translator, crisis room, search engine'
    msg_dict = pyCiscoSpark.post_message(api.config['ACCESS_TOKEN'],
                                         space['id'], msg)
    sEvent('Initial messages recorded:\n\n' + msg)
    wEvent('newSub', session['uid'], 'Messages put in the space', 'OK')

    # End of first inital TechRequest
    session['filename'] = ''
    return 'Space created and people invited'
Esempio n. 9
0
def updateSub():
    error = None

    # Get param
    description = str(request.form['description'])
    if not description:
        wEvent('updateSub', session['uid'], 'Thanks to provide description',
               'KO')
        return 'Thanks to provide description'

    msg = 'TechRequest udpate from ' + session['grp']
    msg += '\n- Description: ' + description

    try:
        severity = str(request.form['severity'])
        if severity:
            msg += '\n- Severity: ' + severity
            try:
                exeReq("UPDATE spaces SET severity = '" + severity +
                       "' WHERE sid = '" + session['sid'] + "';")
            except Exception as e:
                wEvent('updateSub', session['uid'],
                       'Issue during severity update in local DB', 'KO')
    except Exception as e:
        wEvent('updateSub', session['uid'], 'Issue during severity treatment',
               'OK')

    fileurl = 'no file provided'
    if 'filename' in session:
        if session['filename']:
            wEvent('updateSub', session['uid'],
                   'File provided: ' + session['filename'], 'OK')
            fileurl = api.config['UPLOAD_URL'] + session['filename']
            fileurlspark = api.config['UPLOAD_URL_SPARK'] + session['filename']
            msg += '\n- File: ' + fileurl
        else:
            wEvent('updateSub', session['uid'], 'No filename provided', 'KO')
    else:
        wEvent('updateSub', session['uid'], 'No file provided', 'KO')

    # Post file in the Space
    if fileurl != 'no file provided':
        try:
            file_dict = pyCiscoSpark.post_file(api.config['ACCESS_TOKEN'],
                                               session['sid'], fileurlspark)
            wEvent(
                'updateSub', session['uid'], "File " + session['filename'] +
                " posted to the space " + session['sid'], 'KO')
        except Exception as e:
            wEvent(
                'updateSub', session['uid'], "Issue when post file url " +
                fileurl + " to the space " + session['sid'], 'KO')

    # Post TechRequest update messages in the Space
    session['filename'] = ''
    try:
        msg_dict = pyCiscoSpark.post_message(api.config['ACCESS_TOKEN'],
                                             session['sid'], msg)
        return 'Update done'
    except Exception as e:
        wEvent('updateSub', session['uid'], "Issue during message update",
               'KO')
        return render_template('update.html')
Esempio n. 10
0
print "\n\n"
f.write("text:" + message)

#LOOP PREVENTION - this section won't execute if "robot" is at beginning of new posted message - if it isn't it will post a new message with "robot" as prefix
if ((message.find("Google", 0, 6)) == 0):
    searchterm = message[7:]
    print searchterm
    resp_dict = get_google(searchterm)
    print resp_dict
    newmessage = "Response from Google: " + resp_dict["responseData"][
        "results"][0]["title"] + " " + resp_dict["responseData"]["results"][0][
            "url"]
    newmessage = newmessage.replace("<b>", "")
    newmessage = newmessage.replace("</b>", "")
    print newmessage
    resp2_dict = pyCiscoSpark.post_message(accesstoken, roomid, newmessage)
    newmessage = "Response from Google: " + resp_dict["responseData"][
        "results"][1]["title"] + " " + resp_dict["responseData"]["results"][1][
            "url"]
    print newmessage
    newmessage = newmessage.replace("<b>", "")
    newmessage = newmessage.replace("</b>", "")
    resp2_dict = pyCiscoSpark.post_message(accesstoken, roomid, newmessage)
    print resp2_dict

if ((message.find("GPIC", 0, 4)) == 0):
    searchterm = message[5:]
    print searchterm
    resp_dict = get_googlepics(searchterm)
    print resp_dict
    newimage = resp_dict["items"][0]["link"]