-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacro_Storage_Gauge.js
61 lines (49 loc) · 2.31 KB
/
Macro_Storage_Gauge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/********************************************************
Copyright (c) 2024 Cisco and/or its affiliates.
This software is licensed to you under the terms of the Cisco Sample
Code License, Version 1.1 (the "License"). You may obtain a copy of the
License at
https://developer.cisco.com/docs/licenses
All use of the material herein must be in accordance with the terms of
the License. All rights not expressly granted by the License are
reserved. Unless required by applicable law or agreed to separately in
writing, software distributed under the License is distributed on an "AS
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied.
*********************************************************
* Author(s): Robert(Bobby) McGonigle Jr
* Technical Marketing Engineer
* Cisco Systems
*/
import xapi from 'xapi';
function estimateFileSize(text) {
const characterCount = text.length;
const bytes = characterCount;
const kilobytes = Math.round((bytes / 1024) * 10000) / 10000;
const megabytes = Math.round((kilobytes / 1024) * 10000) / 10000;
return { bytes: bytes, kilobytes: kilobytes, megabytes: megabytes, };
}
async function analyzeMacroEnvironment() {
const macros = await xapi.Command.Macros.Macro.Get({ Content: 'True' });
let totals = { bytes: 0, kilobytes: 0, megabytes: 0 };
macros.Macro.forEach(element => {
let fileSizes = estimateFileSize(element.Content);
totals.bytes = totals.bytes + fileSizes.bytes;
totals.kilobytes = totals.kilobytes + fileSizes.kilobytes;
totals.megabytes = totals.megabytes + fileSizes.megabytes;
macros.Macro['Size'] = fileSizes.bytes;
});
totals.kilobytes = Math.round((totals.bytes / 1024) * 100) / 100;
totals.megabytes = Math.round((totals.kilobytes / 1024) * 100) / 100;
generateProgressBar(totals.kilobytes);
}
function generateProgressBar(x) {
const progressBarLength = 20;
const completed = Math.round((x / 2048) * progressBarLength);
const remaining = progressBarLength - completed;
const progressBar = '🟥'.repeat(completed) + '🟩'.repeat(remaining);
const percentage = ((x / 2048) * 100).toFixed(2);
console.log(`Storage Storage: ${progressBar} ${percentage}% used`);
return `${progressBar} ${percentage}%`;
}
analyzeMacroEnvironment();