-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: djerfy <[email protected]>
- Loading branch information
Showing
7 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from modules.kubernetes.openebs.cstorpoolclusters import openebsGetCstorpoolclusters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from kubernetes import client | ||
from pyzabbix import ZabbixMetric | ||
from modules.common.functions import * | ||
import json, urllib3 | ||
|
||
urllib3.disable_warnings() | ||
|
||
def openebsGetCstorpoolclusters(config=None): | ||
""" | ||
description: get cstorpoolclusters data | ||
return: list | ||
""" | ||
kubernetes = client.CustomObjectsApi() | ||
|
||
cstorpoolclusters = [] | ||
|
||
for cstorpoolcluster in rawObjects(kubernetes.list_cluster_custom_object(group="cstor.openebs.io", version="v1", plural="cstorpoolclusters")): | ||
json = { | ||
"name": cstorpoolcluster.metadata.name, | ||
"namespace": cstorpoolcluster.metadata.namespace, | ||
"instances": { | ||
"desired": cstorpoolcluster.status.desiredInstances, | ||
"healthy": cstorpoolcluster.status.healthyInstances, | ||
"provisioned": cstorpoolcluster.status.provisionedInstances | ||
}, | ||
"version": { | ||
"desired": cstorpoolcluster.status.versionDetails.desired, | ||
"current": cstorpoolcluster.status.versionDetails.status.current | ||
} | ||
} | ||
|
||
if matchLabels(config['labels']['exclude'], cstorpoolcluster.metadata.labels): | ||
continue | ||
|
||
if config['labels']['include'] != []: | ||
if not matchLabels(config['labels']['exclude'], cstorpoolcluster.metadata.labels): | ||
continue | ||
|
||
if any(c['name'] == json['name'] and c['namespace'] == json['namespace'] for c in cstorpoolclusters): | ||
continue | ||
|
||
cstorpoolclusters.append(json) | ||
|
||
return cstorpoolclusters | ||
|
||
def ZabbixDiscoveryCstorpoolclusters(clustername, cstorpoolclusters=[]): | ||
""" | ||
description: create a discovery for cstorpoolclusters, per namespace | ||
return: class ZabbixMetric | ||
""" | ||
discovery = {"data":[]} | ||
|
||
for cstorpoolcluster in cstorpoolclusters: | ||
output = { | ||
"{#KUBERNETES_OPENEBS_CSTORPOOLCLUSTER_NAMESPACE}": cstorpoolcluster['namespace'], | ||
"{#KUBERNETES_OPENEBS_CSTORPOOLCLUSTER_NAME}": cstorpoolcluster['name']} | ||
discovery['data'].append(output) | ||
|
||
sender = [ZabbixMetric(clustername, "kubernetes.openebs.cstorpoolclusters.discovery", json.dumps(discovery))] | ||
|
||
return sender | ||
|
||
def ZabbixItemCstorpoolclusters(clustername, cstorpoolclusters=[]): | ||
""" | ||
description: create a item for cstorpoolclusters, per namespace | ||
return: class ZabbixMetric | ||
""" | ||
sender = [] | ||
|
||
for cstorpoolcluster in cstorpoolclusters: | ||
sender.append(ZabbixMetric(clustername, f"kubernetes.openebs.cstorpoolclusters.desiredInstances[{cstorpoolcluster['namespace']},{cstorpoolcluster['name']}]", cstorpoolcluster['instances']['desired']),) | ||
sender.append(ZabbixMetric(clustername, f"kubernetes.openebs.cstorpoolclusters.healthyInstances[{cstorpoolcluster['namespace']},{cstorpoolcluster['name']}]", cstorpoolcluster['instances']['healthy']),) | ||
sender.append(ZabbixMetric(clustername, f"kubernetes.openebs.cstorpoolclusters.provisionedInstances[{cstorpoolcluster['namespace']},{cstorpoolcluster['name']}]", cstorpoolcluster['instances']['provisioned']),) | ||
sender.append(ZabbixMetric(clustername, f"kubernetes.openebs.cstorpoolclusters.desiredVersion[{cstorpoolcluster['namespace']},{cstorpoolcluster['name']}]", cstorpoolcluster['version']['desired']),) | ||
sender.append(ZabbixMetric(clustername, f"kubernetes.openebs.cstorpoolclusters.currentVersion[{cstorpoolcluster['namespace']},{cstorpoolcluster['name']}]", cstorpoolcluster['version']['current']),) | ||
|
||
return sender | ||
|
||
def baseOpenebsCstorpoolclusters(mode=None, config=None): | ||
""" | ||
description: monitoring openebs cstorpoolclusters | ||
return: class ZabbixMetric | ||
""" | ||
if mode == "discovery": | ||
return ZabbixDiscoveryCstorpoolclusters(config['kubernetes']['name'], openebsGetCstorpoolclusters(config['monitoring']['openebs'])) | ||
if mode == "item": | ||
return ZabbixItemCstorpoolclusters(config['kubernetes']['name'], openebsGetCstorpoolclusters(config['monitoring']['openebs'])) | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from modules.kubernetes.trivy.vulnerabilityreports import trivyGetVulnerabilityreports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from kubernetes import client | ||
from pyzabbix import ZabbixMetric | ||
from modules.common.functions import * | ||
import json, urllib3 | ||
|
||
urllib3.disable_warnings() | ||
|
||
def trivyGetVulnerabilityreports(config=None): | ||
""" | ||
description: get vulnerabilityreports data | ||
return: list | ||
""" | ||
kubernetes = client.CustomObjectsApi() | ||
|
||
reports = [] | ||
|
||
for vuln in rawObjects(kubernetes.list_cluster_custom_object(group="aquasecurity.github.io", version="v1alpha1", plural="vulnerabilityreports")): | ||
print(vuln['metadata']['name']) | ||
print(vuln['report']['summary']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters