omni-lchen / zabbix-cloudwatch

71 stars 61 forks source link

Lambda function/ELB/Application ELB names #39

Closed dragan1979 closed 5 years ago

dragan1979 commented 5 years ago

This works like a charm, but how to add variable for region/RDS/Lambda/LB names in items/triggers so to know which Lambda/RDS/Any service has issues ? How to distinguish if more than one RDS,for example, are monitored ?

like for SNS template

dragan1979 commented 5 years ago

I managed to get it for Lambda by adding following line

elif aws_service == 'Lambda':
                topic_name = dimensions['FunctionName']
                zabbix_key =  aws_service + '.' + metric_name + '.' + statistics + '["' + account + '","' + aws_region + '","' + topic_name + '"]'

into zabbixCloudWatch.py

omni-lchen commented 5 years ago

@dragan1979 , the script might need a tweak if you add discovery rules, please amend the script to fit your needs, thanks for your comments.

ghost commented 5 years ago

@omni-lchen thanks for reply, i tried to write discover rule (similar to SNS LLD), but no idea how to do it, so i created new items/triggers for every new Lambda/RDS, can you give me some guidance ?

Thanks

omni-lchen commented 5 years ago

@dragan979 , it is all about key value, try to change current function in AWSLLD script, the key has zabbix macro, zabbix macro value is what you add search condition to filter lambda functions, the key has to match what is in the main zabbixCloudWatch script. For RDS, it is better don't use discovery rule.

ghost commented 5 years ago

uh, tried but no luck, tried to use SNS topic as example, i need to create new function for Lambda metric, in similar way as for SNS/SQS, to create triggers for every Lambda function/application load balancer...

ghost commented 5 years ago

Uh !, after couple of hours managed to add Lambda function to awsLLD.py

def getLambda(a, r, c):
    account = a
    aws_account = awsAccount(account)
    aws_access_key_id = aws_account._aws_access_key_id
    aws_secret_access_key = aws_account._aws_secret_access_key
    aws_region = r
    component = c
    # Init LLD Data
    lldlist = []
    llddata = {"data":lldlist}

    # Connect to Lambda service

    conn = awsConnection()
    conn.lambdaConnect(aws_region, aws_access_key_id, aws_secret_access_key)
    lambdaConn = conn._aws_connection

    # Save Lambda function results in a list

    functionResultsList = []
    # Save topic names in a list
    tdata = []

    # Get a list of Lambda Functions

    functionResults = lambdaConn.list_functions()
    functionResultsList.append(functionResults)
    nextmarker = functionResults['NextMarker']
    #print nextmarker

    while nextmarker:
        functionResults=lambdaConn.list_functions(nextmarker)
        functionResultsList.append(functionResults)
        nextmarker = functionResults['NextMarker']

    for la in functionResultsList:
        for l in la['Functions']:
            functionArn = l['FunctionARN']

            lambdaName = re.sub('^arn:aws:lambda:' + r + ':[0-9]+:function:', '', functionArn)
            if re.search(component, lambdaName) and re.search('', lambdaName, re.I):
                tdata.append(lambdaName)

    if tdata:
        for x in tdata:
            dict = {}
            # Get aws account
            dict["{#AWS_ACCOUNT}"] = a
            # Get aws region
            dict["{#AWS_REGION}"] = r
            # Get topic name
            dict["{#FUNCTION_NAME}"] = x
            # Get short topic name by removing component name
            dict["{#FUNCTION_INAME}"] = re.sub(component + '(-?)', '', x)
            lldlist.append(dict)

    # Print LLD data in json format
    print json.dumps(llddata, indent=4)

#added to the end of file:

 elif query == 'LambdaFunction':
        getLambda(account, region, component)

awsConnection.py:

 # Lambda  connection
 import boto.awslambda
import boto.awslambda.layer1
    def lambdaConnect(self, region, access_key, secret_key):
        self._aws_connection = boto.awslambda.connect_to_region(region, aws_access_key_id=access_key, aws_secret_access_key=secret_key)

#get all functions:

./awsLLD.py -a default -r eu-west-1 -q 'LambdaFunction' -c ''