Skip to content

Commit

Permalink
Added webex func
Browse files Browse the repository at this point in the history
  • Loading branch information
labeveryday committed May 28, 2021
1 parent 878c809 commit 757047a
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 24 deletions.
46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@ ___
1. Build your app:

```bash
intro-to-python-buildpacks git:(main) ✗ tree -L 2
startnow-Intro-to-Python-buildpacks git:(main) ✗ tree -L 2
.
├── LICENSE
├── Procfile
├── README.md
├── __init__.py
├── app
│ ├── __init__.py
│ └── aci_conn.py
│ ├── aci_conn.py
│ └── aci_webex.py
├── cards
│ └── card.json
├── images
│ ├── devi.jpeg
│ ├── image.png
│ └── results.png
├── main.py
├── requirements.txt
├── tenant_log.txt
Expand All @@ -60,7 +67,7 @@ ___
pack --version
```

5. Now create the default builder that will be used for packeto. A builder includes the buildpacks and everything we need like our environment for building our python app.
5. Create the default builder that will be used for packeto. A builder includes the buildpacks and everything we need like our environment for building our python app.

```bash
pack config default-builder paketobuildpacks/builder:full
Expand Down Expand Up @@ -92,14 +99,45 @@ ___

![image](./images/image.png "Docker image")

9. Last thing to do is run our app:
9. It's time to run our app:
```bash
docker run myaciapp
```
![Results](./images/results.png "Myapp Results")
10. Our app gives us the ability to pass in command line arguments when we run our docker container. This gives up the ability to changes our ACI login params as well as provide our `webex_token` and the name of our `webex_room` to send out aci status update message.
```bash
➜ startnow-Intro-to-Python-buildpacks git:(main) ✗ docker run \
> -e webex_token="OWNlMjFhNGMtOG2cae0e10f" \
> -e webex_room="DuAn AciDemo Room" \
> myaciapp
```
```bash
(venv) ➜ startnow-Intro-to-Python-buildpacks git:(main) ✗ python main.py --help
usage: main.py [-h] [--url URL] [--username USERNAME] [--password PASSWORD]
[--webex_token WEBEX_TOKEN] [--webex_room WEBEX_ROOM]
Arguments: url, username, password, webex_token, webex_room
optional arguments:
-h, --help show this help message and exit
--url URL Optional argument to pass url or ip of APIC Default:
'https://sandboxapicdc.cisco.com'
--username USERNAME Optional argument to pass username for APIC user
Default: 'admin'
--password PASSWORD Optional argument to pass password for FMC user
Default: 'ciscopsdt'
--webex_token WEBEX_TOKEN
Optional argument to pass webex api token
--webex_room WEBEX_ROOM
Optional argument to pass webex room name ***NOTE***
arg must be passed with token
```
___
## Notes
Expand Down
63 changes: 63 additions & 0 deletions app/aci_webex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
"""
Script leverages the WebexTeamssdk
Sends a webex teams message
Will create room if not created
Deletes a supplied webex room
To obtain a webex token https://developer.webex.com/
"""
from webexteamssdk import WebexTeamsAPI


def get_webex_token(webex_access_token):
"""
Get developer webex token to be used for future request
Arguments:
webex_access_token (str): Webex developer api token
return: Return API Token
rtype: obj
"""
return WebexTeamsAPI(webex_access_token)

def send_webex_message(webex_token, webex_room, webex_email=None,
webex_message=None, webex_card=None):
"""
Send a message to a supplied webex room
Creates room if not listed
Arguments:
webex_token (cls): Api token for future requests
webex_room (str): Name of webex room
webex_email (str): Email to be added to the webex room
webex_message (str): Str message to be sent
webex_card (dict): Adaptive card for webex message
"""
rooms = webex_token.rooms.list()
aci_room = [room.id for room in rooms if room.title == webex_room]
if aci_room:
if webex_card:
webex_token.messages.create(aci_room[0], text='\n',
attachments=webex_card)
else:
webex_token.messages.create(aci_room[0], markdown=webex_message)
else:
webex_room = webex_token.rooms.create(webex_room)
webex_token.memberships.create(webex_room.id, personEmail=webex_email)
webex_token.messages.create(webex_room.id, text=webex_message)

def delete_webex_room(webex_token, webex_room):
"""
Send a message to a supplied webex room
Creates room if not listed
Arguments:
message (str): Str message to be sent
webex_token (cls): Api token for future requests
webex_room (str): Name of webex room
webex_email (str): Email to be added to the webex room
"""
rooms = webex_token.rooms.list()
aci_room = [room.id for room in rooms if room.title == webex_room]
if aci_room:
webex_token.rooms.delete(aci_room[0])
print(f"Sucessfully deleted {webex_room}")
else:
print(f"Webex room {webex_room}: Not Found")
150 changes: 150 additions & 0 deletions cards/card.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
[
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content":

{
"type": "AdaptiveCard",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"style": "Person",
"url": "https://raw.githubusercontent.com/kiskander/assets/main/mask-icon-01.jpg",
"size": "Medium",
"height": "50px"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "Cisco DNA Center",
"weight": "Lighter",
"color": "Accent"
},
{
"type": "TextBlock",
"weight": "Bolder",
"text": "Contact Tracing",
"horizontalAlignment": "Left",
"wrap": true,
"color": "Light",
"size": "Large",
"spacing": "Small"
}
],
"width": "stretch"
}
]
},
{
"type": "TextBlock",
"text": "Fill in the form below to generate a report based on an identified Pandemic Positive Employee.",
"wrap": true
},
{
"type": "TextBlock",
"text": "Username:",
"wrap": true,
"weight": "Bolder",
"color": "Attention"
},
{
"type": "Input.Text",
"style": "text",
"id": "username",
"placeholder": "Enter a valid username",
"spacing": "Small",
"value": "kevinm"
},
{
"type": "TextBlock",
"text": "Select number of days to trace:",
"weight": "Bolder",
"color": "Attention",
"horizontalAlignment": "Left",
"wrap": true
},
{
"type": "Input.Number",
"id": "report_days",
"placeholder": "Pick number of days between 1-14",
"spacing": "Small",
"min": 0,
"max": 14,
"value": 14
},
{
"type": "TextBlock",
"text": "Enter potential exposure time (min):",
"wrap": true,
"weight": "Bolder",
"color": "Attention"
},
{
"type": "Input.ChoiceSet",
"id": "exposure_time",
"placeholder": "Select 5, 10 or 15 minutes",
"spacing": "Small",
"min": 0,
"max": 15,
"choices": [
{
"title": "5 Min",
"value": "5"
},
{
"title": "10 Min",
"value": "10"
},
{
"title": "15 min",
"value": "15"
}
],
"value": "15"
},
{
"type": "TextBlock",
"text": "Additional Notes:",
"wrap": true,
"weight": "Bolder",
"color": "Attention"
},
{
"type": "Input.Text",
"style": "text",
"id": "notes",
"placeholder": "Attach additional Notes to the final report",
"isMultiline": true
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Generate Report",
"data": {
"subscribe": true
},
"id": "submit"
}
],
"horizontalAlignment": "Left",
"spacing": "None"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2"
}
}
]
Binary file added images/devi.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/passing_args.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 757047a

Please sign in to comment.