Code Monkey home page Code Monkey logo

zabbix-cloudwatch's Introduction

zabbix-cloudwatch

Cloudwatch integration for Zabbix 3.x

Current release: 1.1.0. Zabbix template was tested with Zabbix 3.4, please revert to 1.0.0 if you find any backward incompatibility and open an issue.

Python 2.7.x

  1. Create specialized user account in AWS and grant it permissions for required services and API calls (for example describe_instances() for EC2)
  2. Clone github repo: https://github.com/wawastein/zabbix-cloudwatch
  3. Copy contents of zabbix-scripts into /usr/lib/zabbix directory, change owner of the dir and its contents to user under which you run Zabbix
  4. Install system-wide boto3 package
  5. Import cloudwatch_template.xml into Zabbix
  6. Put credentials of account created in (1) into /usr/lib/zabbix/scripts/conf/aws.conf
  7. Create host with 0.0.0.0 as interface and link it to the template. Change macros ACCOUNT and REGION to correspond to your case:

example

  1. Enable/Disable all discovery rules/items/triggers you think necessary, add new or modify existing ones.

Default template has rules and items for following services:

  • EC2 (requires describe_instances() API call permissions)
  • RDS (describe_db_instances() API call)
  • ELB (describe_load_balancers() API call)
  • EMR (list_clusters() API call)
  • ELBv2 (describe_target_groups() API call)
  • S3 (list_buckets() API call)

Detailed overview at: https://wordpress.com/read/feeds/49943587/posts/1417437611

Hit me up on twitter @wawastein if you got any questions, submit pull requests, fork all you want, and Papa bless.

zabbix-cloudwatch's People

Contributors

adonoga avatar diego-sainz-g avatar jfchevrette avatar wawastein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zabbix-cloudwatch's Issues

Get -1 on elbv2 UnHealthyHostCount

Hi,

I'have read multiple topic on issue and i've search on cloudwatch but i haven't more idea.
On zabbix i get "-1" on elbv2 UnHealthyHostcount but i've data on cloudwatch:

image

I've put 2 lines on script for print time:

/usr/lib/zabbix/scripts/cloudwatch.metric --interval 10800 --metric UnHealthyHostCount --namespace "AWS/ApplicationELB" --statistic Maximum --region region --dimension "LoadBalancer=net/xxxxxxxxxxx,TargetGroup=targetgroup/xxxxxxxxx" --account account-name --debug DEBUG

2022-04-04 16:29:40.965166

2022-04-04 13:29:40.965166

{u'Datapoints': [], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': 'xxxxxxxxxxxx', 'HTTPHeaders': {'x-amzn-requestid': 'xxxxxxxxxxxxxx', 'date': 'Mon, 04 Apr 2022 16:29:40 GMT', 'content-length': '341', 'content-type': 'text/xml'}}, u'Label': 'UnHealthyHostCount'}
-1

Any idea?

Thank you for your script.

S3 bucket has no data points (all buckets)

For all buckets i get "no data points" and values for all buckets is -1, when i change trigger values to different than -1 alert remains

{Cloudwatch Template:cloudwatch.metric[600,BucketSizeBytes,AWS/S3,Average,{$REGION},"BucketName={#BUCKET_NAME},StorageType=StandardStorage",{$ACCOUNT}].last()}<>-1 or
{Cloudwatch Template:cloudwatch.metric[600,NumberOfObjects,AWS/S3,Average,{$REGION},"BucketName={#BUCKET_NAME},StorageType=AllStorageTypes",{$ACCOUNT}].last()}<>-1

RDS No data in zabbix

./aws_discovery.py --service rds --region eu-west-1 --account default
{"data": [{"{#RDS_ID}": "test", "{#STORAGE}": 21474836480}]}

vi /usr/lib/zabbix/externalscripts/
aws.discovery cloudwatch.metric job.list

but nothing shows in Monitoring-Latest data

Support for elbv2

Hi,
Will be that possible to get support for elbv2
http://boto3.readthedocs.io/en/latest/reference/services/elbv2.html#client

I'm not good at python.
But I did notice the same on aws-cli
on one account i have 3 ELB - one classic and two applications.
In AWSCLI
$ aws elb describe-load-balancers|jq ".LoadBalancerDescriptions[].LoadBalancerName"|wc -l
1
and I start to searching what is going on here, and the answer is
$ aws elbv2 describe-load-balancers|jq ".LoadBalancers[].LoadBalancerArn"|wc -l
2

Please kindly notice that the out put is totally different.

Discovery error

Configured as per the step and I am trying to execute discoverer for each of the services like ec2, emr, rds etc. It shows an error as below:

Invalid discovery rule value: cannot parse as a valid JSON object:
invalid object format, expected opening character '{' or '[' at: 'File
"./aws_discovery.py", line 44
print d.get_instances(*args.args)
^
SyntaxError: invalid syntax'

Hitting a major roadblock because of this.

ConfigParser error

Another error:

File "/usr/lib/zabbix/scripts/discovery/ec2.py", line 2, in
from basic_discovery import BasicDiscoverer
ModuleNotFoundError: No module named 'basic_discovery'

I dont see BasicDiscoverer under python3 modules.

Please help soon. @wawastein

Changing name removes the graph data

Hi,

Not sure why but for some reason if I change the hostname or set a 'Visible Name' for the AWS host, it just removes all the data on the graphs?

How to do Steps 8?

Hi,
Can you elaborate how to enable rules/items/trigger? In your guide, i also didn't see any thing about "executing external script". Not sure if i have to do that or not.
Right now after creating new host, linked cloudwatch template, setup MACRO. I didn't see any items.
In my case, i just want to see graph of all ELB's metric for a specific ELB (i have 3 ELB running).
How can i do that?

Should be a way to use an IAM Role

Our cloud team will only create Roles in AWS rather than individual IAM users with keys. There should be a way to specify a Role OR user with keys.

Multiple AWS zones

1

2

But, instead of EC2 instances from both regions i got only instances from us-east-1 duplicated

Cannot seem to make the scripts working on Ubuntu 20.04

In Ubuntu, python packages are installed as either python2 or python3.
There's no /usr/bin/python executable, but
ls -alh /usr/bin/pyt* lrwxrwxrwx 1 root root 9 Mar 13 2020 /usr/bin/python2 -> python2.7 -rwxr-xr-x 1 root root 3.5M Aug 4 11:16 /usr/bin/python2.7 lrwxrwxrwx 1 root root 9 Mar 13 2020 /usr/bin/python3 -> python3.8 lrwxrwxrwx 1 root root 16 Mar 13 2020 /usr/bin/python3-config -> python3.8-config -rwxr-xr-x 1 root root 5.3M Jul 28 12:59 /usr/bin/python3.8 lrwxrwxrwx 1 root root 33 Jul 28 12:59 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config

I tried changing the script to have #!/usr/bin/python2 at the beginning, but trying to run /usr/lib/zabbix/scripts/aws_discovery.py --account default --region eu-west-1 --service s3

I get

Traceback (most recent call last):
  File "/usr/lib/zabbix/scripts/aws_discovery.py", line 43, in <module>
    args.service, args.region)
  File "/usr/lib/zabbix/scripts/discovery/aws_client.py", line 9, in __init__
    aws_key = config.get(account, "key")
  File "/usr/lib/python2.7/ConfigParser.py", line 607, in get
    raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'default'

Configured template discovery rule shows error

Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: '/usr/lib/zabbix/externalscripts/aws.discovery: ./aws_discovery.py: /usr/bin/python: bad interpreter: No such file or directory'

Import cloudwatch_template.xml failed

zabbix 4.0 lts

when i import the cloudwatch_template.xml i get the following error

Invalid key "instances[{#TARGET_GROUP_LOAD_BALANCER_NAME}][{#TARGET_GROUP_NAME}]" for item prototype "ELBv2: {#TARGET_GROUP_LOAD_BALANCER_NAME} target group {#TARGET_GROUP_NAME} total targets" on "Cloudwatch Template": incorrect syntax near "[{#TARGET_GROUP_NAME}]".

Error with module discovery

Hello,

thank you for your work! I used with my old ZAbbix V4.

i've a new Zabbix v6, I made change in the script, but I ve this error:

Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: 'Traceback (most recent call last):
File "./aws_discovery.py", line 39, in
"discovery")
File "/usr/lib/python3.7/importlib/init.py"

Do you know how I can fix that?

Best regards,

Seb

import template error

I have receive the error when I try to import template file to zabbix front.
image

I have done following steps:

  1. place the "externalscripts" and "scripts" to /usr/lib/zabbix
  2. change both directory files to 755 right.

Received value not suitable for type Numeric (float)

Discovery works - I can see objects (like S3 buckets) but there are no values and on item list I can see that all of them have not supported status with error as below:

Received value [Traceback (most recent call last): File "./cloudwatch.metric", line 94, in <module> dimensions=dimensions) File "./cloudwatch.metric", line 20, in get_metric Period=interval) File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 314, in _api_call return self._make_api_call(operation_name, kwargs) File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 612, in _make_api_call raise error_class(parsed_response, operation_name)botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the GetMetricStatistics operation: Signature not yet current: 20180307T081832Z is still later than 20180307T081739Z (20180307T081239Z + 5 min.)] is not suitable for value type [Numeric (float)]

ELB Aplication type doesn't work

Hi,

I'v created template based on your script, but when I'm using "AWS/ApplicationELB" namespace I get error "Received value [-1] is not suitable for value type [Numeric (unsigned)] and data type [Decimal"

image

Receiving negative values

Hi,
You did a great job. Many thanks!
But there is a problem, I receiving negative values -1 instead of 0.

image

Support for ECS?

Hi,

Does this support discovery and monitoring of ECS instances?
Is it possible to add this?

Thanks

Support for RDS Aurora Clusters

Dear Diego,

As you recommend me I have opened a new issue to talk about RDS Aurora cluster in a new thread.
I have posted here our last commentaries.
To sum up, You have given me a perfect solution to monitor only rds clusters but my need is to monitor both (instances and clusters). Then, I asked you again for help.
What I need is to merge both scripts because aws_discovery.py only can run one rds.py. It does not recognize any other script called rds-xxxxx.py

Thank you very much again.

Another problem I have is that I will need to monitor RDS Aurora cluster. In this case, the dimension should change from DBInstanceIdentifier to DBClusterIdentifier. Then, I should change or create a new rds.py because the current rds.py only works with DBInstanceIdentifier

I have no idea of Python. Would you mind help me? What changes will do you do in rds.py? Is it enough to only change rds.py or I have to change more files?

This is my rds.py file:
[root@salt-master discovery]# cat rds.py
#!/usr/bin/python
from basic_discovery import BasicDiscoverer
class Discoverer(BasicDiscoverer):
def discovery(self, *args):
response = self.client.describe_db_instances()
data = list()
for instance in response["DBInstances"]:
storage_bytes = int(instance["AllocatedStorage"]) * pow(1024, 3)
ldd = {
"{#STORAGE}": storage_bytes,
"{#RDS_ID}": instance["DBInstanceIdentifier"]
}
data.append(ldd)
return data

I should add to this file this information but I do not have an idea of python:
response = self.client.describe_db_clusters()
data = list()
for cluster in response["DBClusters"]:
storage_bytes = int(cluster["AllocatedStorage"]) * pow(1024, 3)
ldd = {
"{#STORAGE}": storage_bytes,
"{#RDS_CLUSTER_ID}": cluster["DBClusterIdentifier"]
}
data.append(ldd)
return data
..........................................................................
To monitor Aurora RDS clusters you are in the right path. You don't really need to know Python to modify the script (just the basic syntax details). The current rds.py script will correctly discover the instances, but if you want to have also the data at cluster level the following should work:

#!/usr/bin/python
from basic_discovery import BasicDiscoverer

class Discoverer(BasicDiscoverer):
def discovery(self, *args):
response = self.client.describe_db_clusters()
data = list()

    for cluster in response["DBClusters"]:

        storage_bytes = int(cluster["AllocatedStorage"]) * pow(1024, 3)
        for instance in cluster["DBClusterMembers"]:

            data.append({
                "{#CLUSTER_ID}": cluster["DBClusterIdentifier"],
                "{#STORAGE}": storage_bytes,
                "{#MEMBER_ID}": instance["DBInstanceIdentifier"]
             })

    return data

This will output the following:

{
"data": [
{
"{#CLUSTER_ID}": "myCluster01",
"{#MEMBER_ID}": "myInstance01",
"{#STORAGE}": 1073741824
},
{
"{#CLUSTER_ID}": "myCluster01",
"{#MEMBER_ID}": "myInstance02",
"{#STORAGE}": 1073741824
}
]
}
...........................
[root@salt-master zabbix]# ./aws_discovery.py --service rds-bak --region eu-west-1 --account xxxxxx
Traceback (most recent call last):
File "./aws_discovery.py", line 43, in
args.service, args.region)
File "/usr/lib/zabbix/discovery/aws_client.py", line 15, in init
region_name=region)
File "/usr/lib/python2.7/site-packages/boto3/init.py", line 79, in client
return _get_default_session().client(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/boto3/session.py", line 192, in client
aws_session_token=aws_session_token, config=config)
File "/usr/lib/python2.7/site-packages/botocore/session.py", line 835, in create_client
client_config=config, api_version=api_version)
File "/usr/lib/python2.7/site-packages/botocore/client.py", line 76, in create_client
service_model = self._load_service_model(service_name, api_version)
File "/usr/lib/python2.7/site-packages/botocore/client.py", line 114, in _load_service_model
api_version=api_version)
File "/usr/lib/python2.7/site-packages/botocore/loaders.py", line 132, in _wrapper
data = func(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/botocore/loaders.py", line 378, in load_service_model
known_service_names=', '.join(sorted(known_services)))
botocore.exceptions.UnknownServiceError: Unknown service: 'rds-bak'. Valid service names are: accessanalyzer, acm, acm-pca, alexaforbusiness, amplify, apigateway, apigatewaymanagementapi, apigatewayv2, appconfig, application-autoscaling, application-insights, appmesh, appstream, appsync, athena, autoscaling, autoscaling-plans, backup, batch, budgets, ce, chime, cloud9, clouddirectory, cloudformation, cloudfront, cloudhsm, cloudhsmv2, cloudsearch, cloudsearchdomain, cloudtrail, cloudwatch, codebuild, codecommit, codedeploy, codeguru-reviewer, codeguruprofiler, codepipeline, codestar, codestar-connections, codestar-notifications, cognito-identity, cognito-idp, cognito-sync, comprehend, comprehendmedical, compute-optimizer, config, connect, connectparticipant, cur, dataexchange, datapipeline, datasync, dax, detective, devicefarm, directconnect, discovery, dlm, dms, docdb, ds, dynamodb, dynamodbstreams, ebs, ec2, ec2-instance-connect, ecr, ecs, efs, eks, elastic-inference, elasticache, elasticbeanstalk, elastictranscoder, elb, elbv2, emr, es, events, firehose, fms, forecast, forecastquery, frauddetector, fsx, gamelift, glacier, globalaccelerator, glue, greengrass, groundstation, guardduty, health, iam, imagebuilder, importexport, inspector, iot, iot-data, iot-jobs-data, iot1click-devices, iot1click-projects, iotanalytics, iotevents, iotevents-data, iotsecuretunneling, iotthingsgraph, kafka, kendra, kinesis, kinesis-video-archived-media, kinesis-video-media, kinesis-video-signaling, kinesisanalytics, kinesisanalyticsv2, kinesisvideo, kms, lakeformation, lambda, lex-models, lex-runtime, license-manager, lightsail, logs, machinelearning, macie, managedblockchain, marketplace-catalog, marketplace-entitlement, marketplacecommerceanalytics, mediaconnect, mediaconvert, medialive, mediapackage, mediapackage-vod, mediastore, mediastore-data, mediatailor, meteringmarketplace, mgh, migrationhub-config, mobile, mq, mturk, neptune, networkmanager, opsworks, opsworkscm, organizations, outposts, personalize, personalize-events, personalize-runtime, pi, pinpoint, pinpoint-email, pinpoint-sms-voice, polly, pricing, qldb, qldb-session, quicksight, ram, rds, rds-data, redshift, rekognition, resource-groups, resourcegroupstaggingapi, robomaker, route53, route53domains, route53resolver, s3, s3control, sagemaker, sagemaker-a2i-runtime, sagemaker-runtime, savingsplans, schemas, sdb, secretsmanager, securityhub, serverlessrepo, service-quotas, servicecatalog, servicediscovery, ses, sesv2, shield, signer, sms, sms-voice, snowball, sns, sqs, ssm, sso, sso-oidc, stepfunctions, storagegateway, sts, support, swf, textract, transcribe, transfer, translate, waf, waf-regional, wafv2, workdocs, worklink, workmail, workmailmessageflow, workspaces, xray

Best Regards

Support for Tags

Hello,
Thank you for your great work!
I would like to be able to monitor only resources with specified tags (e.g. Monitoring=True). If you have over 100 resources, and you don't want to get alerts for most of them, you want to filter resources by tags.
I succeeded to do that for EC2 and for RDS, but for ELBv2 for example it's a bit harder, because you need to get the resources from resourcegroupstaggingapi first, to get the ARN of all loadbalancers by tags, and after that, get the resources from elbv2 api.

Can I ask to add the possibility to discover only the resources based on the tags ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.