Skip to content

Commit

Permalink
Merge pull request #90 from 4urcloud/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
aeppling authored Dec 8, 2023
2 parents 0adf4f2 + 1898b5f commit 998a3bb
Show file tree
Hide file tree
Showing 30 changed files with 2,074 additions and 855 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ eastern-rider-263712-9376010a1184.json
config/addOnNeed.json
config/headers.json
config_kuber
output/*
output/*
savedFolder/*
178 changes: 178 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,181 @@ documentation/Documentation-Kexa.md was changed
initKexa.ps1 was changed


## 1.8.0-SNAPSHOT.113.3054896

### Files added: 0

### Files changed: 1

README.md was changed


## 1.8.0-SNAPSHOT.118.4150a43

### Files added: 0

### Files changed: 3

Kexa/services/addOn/azureGathering.service.ts was changed

Kexa/services/analyse.service.ts was changed

initKexa.ps1 was changed


## 1.8.0-SNAPSHOT.124.7d39677

### Files added: 0

### Files changed: 2

.gitignore was changed

initKexa.ps1 was changed


## 1.8.0-SNAPSHOT.127.e802885

### Files added: 0

### Files changed: 3

Kexa/rules/OperationalExcellence.yaml was changed

Kexa/services/addOn/azureGathering.service.ts was changed

Kexa/services/addOn/display/azureDisplay.service.ts was changed


## 1.8.0-SNAPSHOT.129.168f9b5

### Files added: 0

### Files changed: 2

README.md was changed

documentation/Documentation-Kexa.md was changed


## 1.8.0-SNAPSHOT.132.427091f

### Files added: 0

### Files changed: 1

README.md was changed


## 1.8.0-SNAPSHOT.135.a605443

### Files added: 0

### Files changed: 1

README.md was changed


## 1.10.0-SNAPSHOT.25.9ee4861

### Files added: 0

### Files changed: 0


## 1.10.0-SNAPSHOT.29.a6375e2

### Files added: 0

### Files changed: 13

Kexa/main.ts was changed

Kexa/models/settingFile/config.models.ts was changed

Kexa/services/addOn.service.ts was changed

Kexa/services/addOn/awsGathering.service.ts was changed

Kexa/services/addOn/azureGathering.service.ts was changed

Kexa/services/addOn/gcpGathering.service.ts was changed

Kexa/services/addOn/githubGathering.service.ts was changed

Kexa/services/addOn/googleWorkspaceGathering.service.ts was changed

Kexa/services/addOn/kubernetesGathering.service.ts was changed

Kexa/services/addOn/o365Gathering.service.ts was changed

Kexa/services/analyse.service.ts was changed

config/default.json was changed

documentation/Documentation-Kexa.md was changed


## 1.10.0-SNAPSHOT.31.b2209bd

### Files added: 0

### Files changed: 1

package-lock.json was changed


## 1.10.0-SNAPSHOT.34.fd4abd2

### Files added: 3

Kexa/emails/teams.ts was added

Kexa/helpers/extractURL.ts was added

Kexa/helpers/spliter.ts was added

### Files changed: 8

Kexa/emails/teams.ts was changed

Kexa/helpers/extractURL.ts was changed

Kexa/helpers/spliter.ts was changed

Kexa/services/alerte.service.ts was changed

Kexa/services/analyse.service.ts was changed

documentation/Documentation-Kexa.md was changed

package-lock.json was changed

package.json was changed


## 1.10.0-SNAPSHOT.40.9bbdd02

### Files added: 1

Kexa/helpers/statsNumbers.ts was added

### Files changed: 8

Kexa/helpers/statsNumbers.ts was changed

Kexa/main.ts was changed

Kexa/rules/Economy.yaml was changed

Kexa/services/addOn/azureGathering.service.ts was changed

config/default.json was changed

documentation/AWS.md was changed

package-lock.json was changed

package.json was changed


55 changes: 55 additions & 0 deletions Kexa/emails/teams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const levelAlert = ["info", "warning", "error", "fatal"];
export const Teams = {
//https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL
OneTeams: (color:string, subject:string, url:string, description:string) => {
return JSON.stringify({
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": color,
"summary": subject,
"sections": [
{
"activityTitle": subject,
"activitySubtitle": description,
"activityImage": "https://kexa.io/kexa-no-background-color.png",
"markdown": true
}
],
"potentialAction": [
{
"@type": "OpenUri",
"name": "Go to ressource",
"targets": [
{
"os": "default",
"uri": url
}
]
}
]
});
},
GlobalTeams: (color:string, subject:string, text:string, errors:{ [x: string]: number; }) => {
return JSON.stringify({
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": color,
"summary": subject,
"sections": [
{
"activityTitle": subject,
"activitySubtitle": "Kexa by 4urcloud",
"activityImage": "https://kexa.io/kexa-no-background-color.png",
"text": text,
"facts": Object.entries(errors).map(([name, value]) => {
return {
"name": name,
"value": value.toString()
};
}),
"markdown": true
}
]
});
},
};
34 changes: 34 additions & 0 deletions Kexa/helpers/extractURL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const jsdom = require("jsdom")
const { JSDOM } = jsdom
global.DOMParser = new JSDOM().window.DOMParser

export const extractURL = (text: string): string | null => {
return extractFirstURLFromHTML(text)??extractFirstURL(text);
}

function extractFirstURLFromHTML(html: string): string | null {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');

const urlElements = Array.from(doc.querySelectorAll('a[href], img[src]'));

for (const element of urlElements) {
const url = (element as HTMLAnchorElement).href || (element as HTMLImageElement).src;
if (url) {
return url;
}
}

return null;
}

function extractFirstURL(input:string): string | null {
const urlRegex = /(https?:\/\/[^\s]+)/g;
const matches = input.match(urlRegex);

if (matches && matches.length > 0) {
return matches[0];
}

return null;
}
21 changes: 21 additions & 0 deletions Kexa/helpers/spliter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const splitProperty = (prop: string, delimiter:string, ignore:string="/"):string[] => {
const result = [];
let current = "";
let escape = false;

for (const char of prop) {
if (char === delimiter && !escape) {
result.push(current);
current = "";
} else if (char === ignore && !escape) {
escape = true;
} else {
if(escape && char !== delimiter) current += ignore;
current += char;
escape = false;
}
}

result.push(current);
return result;
}
37 changes: 37 additions & 0 deletions Kexa/helpers/statsNumbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export function getMinMaxMeanMedian(array: Array<number>): MinMaxMeanMedian {
let min = array[0];
let max = array[0];
let sum = 0;
for(const num of array){
if(num < min) min = num;
if(num > max) max = num;
sum += num;
}
return {
"min": min,
"max": max,
"mean": sum/array.length,
"median": array[Math.floor(array.length/2)],
}
}

export function convertToPercentage(num: number, total: number): number {
// pourcentage avec 2 chiffres après la virgule
return Math.round((num/total)*10000)/100;
}

export function convertMinMaxMeanMedianToPercentage(stat:MinMaxMeanMedian, total:number): MinMaxMeanMedian {
return {
"min": convertToPercentage(stat.min, total),
"max": convertToPercentage(stat.max, total),
"mean": convertToPercentage(stat.mean, total),
"median": convertToPercentage(stat.median, total),
}
}

export interface MinMaxMeanMedian {
min: number,
max: number,
mean: number,
median: number,
}
4 changes: 1 addition & 3 deletions Kexa/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ export async function main() {
let settings = await gatheringRules(await getEnvVar("RULESDIRECTORY")??"./Kexa/rules");
context?.log("settings", settings);
if(settings.length != 0){
let resources = {};
resources = await loadAddOns(resources);
let resources = await loadAddOns(settings);
context?.log("resources", resources);
if(args.o) createFileSync(JSON.stringify(resources), folderOutput + "/resources/"+ new Date().toISOString().slice(0, 16).replace(/[-T:/]/g, '') +".json", true);
context?.log("good");
settings.forEach(setting => {
context?.log("setting", setting);
let result = checkRules(setting.rules, resources, setting.alert);
logger.debug(result);
if(setting.alert.global.enabled){
let render_table = renderTableAllScan(result.map(scan => scan.filter(value => value.error.length>0)));
let render_table_loud = renderTableAllScanLoud(result.map(scan => scan.filter(value => value.loud)));
Expand Down
1 change: 1 addition & 0 deletions Kexa/models/settingFile/config.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export interface Config {
name?: string;
description?: string;
prefix?: string;
ObjectNameNeed?: Array<string>;
}
17 changes: 16 additions & 1 deletion Kexa/rules/Economy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,19 @@
conditions:
- property: consumedUnits
condition: SUP
value: 0
value: 0
- name: "not-under-use-VM"
description: "this rule is if a VM is under-used (50% > CPU or 50%>RAM over 2 weeks) "
applied: true
level: 1
cloudProvider: azure
objectName: vm
conditions:
- operator: OR
criteria:
- property: instanceView.percentageCPU.mean
condition: SUP
value: 50
- property: instanceView.availableMemoryBytes.mean
condition: SUP
value: 50
Loading

0 comments on commit 998a3bb

Please sign in to comment.