Merge branch 'ent-12104-plugins-de-integracion-de-alertas-por-defecto' into 'develop'

adding ilert integration plugin

See merge request artica/pandorafms!6521
This commit is contained in:
Rafael Ameijeiras 2023-10-18 09:14:19 +00:00
commit 8d7f253e91
17 changed files with 268 additions and 94 deletions

View File

@ -1 +1,3 @@
venv
build
dist
*spec

View File

@ -1,4 +1,4 @@
import requests, argparse, sys, os
import requests, argparse, sys, os, signal
from datetime import datetime
from re import search
from base64 import b64decode
@ -26,6 +26,18 @@ parser.add_argument('--tmp_dir', help='Temporary path to store graph images', de
args = parser.parse_args()
# Define a function to handle the SIGINT signal
def sigint_handler(signal, frame):
print ('\nInterrupted by user')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# Define a function to handle the SIGTERM signal
def sigterm_handler(signum, frame):
print("Received SIGTERM signal.")
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
### Functions:
def parse_dic(cValues):
"""convert coma separate keypairs into a dic. EX "test=5,house=8,market=2" wil return "{'test': '5', 'casa': '8', 'mercado': '2'}" """

View File

@ -0,0 +1,3 @@
build
dist
*spec

View File

@ -1,8 +1,4 @@
import requests
import argparse
import sys
import os
import json
import requests, signal, argparse, sys, os, json
### Variables and arg parser ###
parser = argparse.ArgumentParser(description='Google chat webhook conector')
@ -23,6 +19,18 @@ parser.add_argument('--btn_url', help='button url',
args = parser.parse_args()
# Define a function to handle the SIGINT signal
def sigint_handler(signal, frame):
print ('\nInterrupted by user')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# Define a function to handle the SIGTERM signal
def sigterm_handler(signum, frame):
print("Received SIGTERM signal.")
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
# classes

View File

@ -0,0 +1,3 @@
build
dist
*spec

View File

@ -0,0 +1,78 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "PandoraFMS Team"
__copyright__ = "Copyright 2023, PandoraFMS"
#__credits__ = ["Rob Knight", "Peter Maxwell", "Gavin Huttley", "Matthew Wakefield"]
__maintainer__ = "Projects/QA department"
__status__ = "Test"
__version__ = "1"
import requests, json, sys, argparse, signal, re,datetime
current_date=datetime.datetime.now()
info= f"""
PandoraFMS ilert integration.
Version: {__version__}
"""
parser = argparse.ArgumentParser(description= info, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-a', '--api_key', help='Api key from ilert', required=True)
parser.add_argument('-t', '--event_type', help='Type of the created event. Can be "alert" or "resolved".', type=str, required=True)
parser.add_argument('-k', '--event_key', help='Title of the event, used as key', type=str, required=True)
parser.add_argument('-T', '--title', help='Title of the event.', type=str, required=True)
parser.add_argument('-d', '--description', help='Description of the event', type=str, default='')
parser.add_argument('-A', '--agent_name', help='pandorafms agent name', type=str, default='')
parser.add_argument('-p', '--priority', help='priority', type=str, default='')
parser.add_argument('-m', '--module_name', help='priority', type=str, default='')
parser.add_argument('-D', '--module_data', help='priority', type=str, default='')
parser.add_argument('-C', '--created_date', help='event date', type=str, default=current_date)
args = parser.parse_args()
# Define a function to handle the SIGINT signal
def sigint_handler(signal, frame):
print ('\nInterrupted by user')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# Define a function to handle the SIGTERM signal
def sigterm_handler(signum, frame):
print("Received SIGTERM signal.")
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
# Functions
def post_url(url, data=None, headers={"Accept": "application/json"},):
try :
data = requests.post(url, data=data, headers=headers)
result_data = data.status_code
except Exception as e :
print (f"[red]Error[/red] posting data from {url} {e}", file = sys.stderr )
sys.exit()
return result_data
if __name__ == "__main__":
# Prepare data
url = f"https://api.ilert.com/api/v1/events/pandorafms/{args.api_key}"
payload = {
"eventType": args.event_type,
"title": args.title,
"description": args.description,
"incidentKey": args.event_key,
"details": {
"agentName": args.agent_name,
"createdAt": str(args.created_date),
"priority": args.priority,
"moduleName": args.module_name,
"moduleData": args.module_data
}
}
response=post_url(url, data=json.dumps(payload))
if response == 202: print ("Alert has been submitted!")
print (f"http_code: {response}", file=sys.stderr)

View File

@ -0,0 +1,8 @@
altgraph==0.17.3
certifi==2023.7.22
charset-normalizer==3.3.0
idna==3.4
pyinstaller==5.13.0
pyinstaller-hooks-contrib==2023.7
requests==2.31.0
urllib3==2.0.5

View File

@ -0,0 +1,3 @@
build
dist
*spec

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse, pymsteams
import argparse, pymsteams, signal
parser = argparse.ArgumentParser(description='MS Teams connector')
parser.add_argument('-d', '--data', help='Data in coma separate keypairs. Ex: test=5,house=2', required=True)
@ -16,6 +16,18 @@ parser.add_argument('--button_desc', help='Pandora button description', default=
args = parser.parse_args()
# Define a function to handle the SIGINT signal
def sigint_handler(signal, frame):
print ('\nInterrupted by user')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# Define a function to handle the SIGTERM signal
def sigterm_handler(signum, frame):
print("Received SIGTERM signal.")
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
### Functions:
def parse_dic(cValues):
"""convert coma separate keypairs into a dic. EX "test=5,house=8,market=2" wil return "{'test': '5', 'casa': '8', 'mercado': '2'}" """

View File

@ -1,81 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse, pymsteams
parser = argparse.ArgumentParser(description='MsTeams connector')
parser.add_argument('-d', '--data', help='Data in coma separate keypairs. Ex: test=5,house=2', required=True)
parser.add_argument('-u', '--url', help='Teams webhook URL', required=True)
parser.add_argument('-t', '--alert_tittle', help='Alert tittle', default='PandoraFMS alert fired')
parser.add_argument('-D', '--alert_desc', help='Alert description', default='Alert Fired')
parser.add_argument('-m', '--message', help='Alert message', default='')
parser.add_argument('-T','--tittle_color', help='Alert tittle descripcion in HEX EX: 53e514', default="53e514")
parser.add_argument('--sub_desc', help='Alert sub description', default='Alert Fired')
parser.add_argument('--thumb', help='Custom thumbnail url', default="https://pandorafms.com/images/alerta_roja.png")
parser.add_argument('--button', help='Pandora button Url', default='https://pandorafms.com')
parser.add_argument('--button_desc', help='Pandora button description', default='Open web console')
args = parser.parse_args()
### Functions:
def parse_dic(cValues):
"""convert coma separate keypairs into a dic. EX "test=5,house=8,market=2" wil return "{'test': '5', 'casa': '8', 'mercado': '2'}" """
data={}
try :
for kv in cValues.split(","):
k,v = kv.strip().split("=")
data[k.strip()]=v.strip()
except Exception as e :
print(f"Warning, error parsing keypairs values: {e}")
return data
def add_embed_itmes(data):
"""iterate dictionary and set webhook fields, one for eacj keypair"""
for k, v in data.items() :
myMessageSection.addFact(f"{k}:", v)
##Main
# You must create the connectorcard object with the Microsoft Webhook URL
myTeamsMessage = pymsteams.connectorcard(args.url)
# Set Summary
myTeamsMessage.summary(args.message)
# Set Alert tittle
myTeamsMessage.title(args.alert_tittle)
# Set link buttom
myTeamsMessage.addLinkButton(args.button_desc, args.button)
# Set message color
myTeamsMessage.color(args.tittle_color)
# create the section
myMessageSection = pymsteams.cardsection()
# Section Title
myMessageSection.title(args.message)
# Activity Elements
myMessageSection.activityTitle(args.alert_desc)
myMessageSection.activitySubtitle(args.sub_desc)
myMessageSection.activityImage(args.thumb)
# Facts are key value pairs displayed in a list.
data = parse_dic(args.data)
add_embed_itmes(data)
# Section Text
# myMessageSection.text("This is my section text")
# Section Images
# myMessageSection.addImage("http://i.imgur.com/c4jt321l.png", ititle="This Is Fine")
# Add your section to the connector card object before sending
myTeamsMessage.addSection(myMessageSection)
# Then send the card
try:
myTeamsMessage.send()
except Exception as e :
print(f"Error sending to message: {e}")

View File

@ -1 +1,3 @@
venv
build
dist
*spec

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests, argparse, sys, os
import requests, argparse, sys, os, signal
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from datetime import datetime
@ -26,6 +26,18 @@ parser.add_argument('--tmp_dir', help='Temporary path to store graph images', de
args = parser.parse_args()
filename = None
# Define a function to handle the SIGINT signal
def sigint_handler(signal, frame):
print ('\nInterrupted by user')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# Define a function to handle the SIGTERM signal
def sigterm_handler(signum, frame):
print("Received SIGTERM signal.")
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
#Functions
def parse_dic(cValues):
@ -126,7 +138,7 @@ def send_message(message, channel, client, feddback=None):
assert e.response["ok"] is False
assert e.response["error"] # str like 'invalid_auth', 'channel_not_found'
print(f"Got an Slack auth error: {e.response['error']}")
exit()
sys.exit()
def send_image(imagepath, channel, client) :
"""Send file as slack bot"""
@ -177,4 +189,4 @@ if args.footer: send_message(args.footer, args.channel, client)
try:
os.remove(filename)
except:
exit()
sys.exit()

View File

@ -0,0 +1,3 @@
build
dist
*spec

View File

@ -1,4 +1,4 @@
import requests, argparse, json, sys, os
import requests, argparse, json, sys, os, signal
from datetime import datetime
from base64 import b64decode
@ -27,7 +27,19 @@ def parse_dic(cValues):
print(f"Warning, error parsing keypairs values: {e}")
return data
# Define a function to handle the SIGINT signal
def sigint_handler(signal, frame):
print ('\nInterrupted by user')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# Define a function to handle the SIGTERM signal
def sigterm_handler(signum, frame):
print("Received SIGTERM signal.")
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
#Functions
def parse_api_conf(cConf):
"""Check apiconfiguration parameters """
if args.api_conf :

View File

@ -0,0 +1,3 @@
build
dist
*spec

View File

@ -0,0 +1,78 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "PandoraFMS Team"
__copyright__ = "Copyright 2023, PandoraFMS"
#__credits__ = ["Rob Knight", "Peter Maxwell", "Gavin Huttley", "Matthew Wakefield"]
__maintainer__ = "Projects/QA department"
__status__ = "Test"
__version__ = "1"
import vonage, json, sys, argparse, signal, re,datetime
current_date=datetime.datetime.now()
info= f"""
PandoraFMS vonage integration.
Version: {__version__}
"""
parser = argparse.ArgumentParser(description= info, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-a', '--api_key', help='Client key from vonage', required=True)
parser.add_argument('-s', '--secret', help='Secret key from vonage".', type=str, required=True)
parser.add_argument('-m', '--message', help='Title of the event, used as key', type=str, required=True)
parser.add_argument('-n', '--phone_number', help='Phone number to send sms with country code. Ex: "+34555444111,+34777444222" could be a coma separated list of numbers', type=str, required=True)
parser.add_argument('-f', '--from_alias', help='From number/string data', type=str, default="PandoraFMS")
parser.add_argument('-v', '--verbose', help='Debug information', action='store_true')
args = parser.parse_args()
# Define a function to handle the SIGINT signal
def sigint_handler(signal, frame):
print ('\nInterrupted by user')
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# Define a function to handle the SIGTERM signal
def sigterm_handler(signum, frame):
print("Received SIGTERM signal.")
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
# Functions
def convet_list_comma (data:str):
if "," in data:
result = data.split(",")
else:
result = []
result.append(data)
return result
if __name__ == "__main__":
# Prepare data
client = vonage.Client(key=args.api_key, secret=args.secret)
try:
numbers=convet_list_comma(args.phone_number)
except Exception as e:
print (f"Error: {e}")
sys.exit()
for number in numbers :
responseData = client.sms.send_message(
{
"from": args.from_alias,
"to": number,
"text": args.message,
}
)
if responseData["messages"][0]["status"] == "0":
print("Message sent successfully.")
else:
print(f"Message failed with error: {responseData['messages'][0]['error-text']}")
#debug
if args.verbose == True: print (f"Debug: {responseData}")

View File

@ -0,0 +1,16 @@
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.0
cryptography==41.0.4
Deprecated==1.2.14
idna==3.4
pycparser==2.21
pydantic==1.10.13
PyJWT==2.8.0
pytz==2023.3.post1
requests==2.31.0
typing_extensions==4.8.0
urllib3==2.0.6
vonage==3.9.1
vonage-jwt==1.0.0
wrapt==1.15.0