@synetic/et 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const axios = require('axios');
2
- const yargs = require('yargs')
2
+ const argv = require('yargs/yargs')(process.argv.slice(2)).argv;
3
3
 
4
4
  const { encrypt } = require('./lib/encypt');
5
5
  const { collect } = require('./lib/collector')
@@ -7,26 +7,31 @@ const KEY = process.env.SYNETIC_ET_KEY || '';
7
7
 
8
8
  const HOME_URL = process.env.SYNETIC_ET_HOME || '';
9
9
 
10
- const phoneHome = () => {
10
+ const phoneHome = async () => {
11
11
  console.log(`collecting information to phone home (${HOME_URL})`);
12
- const data = collect();
12
+ const data = await collect();
13
13
  const payload = {
14
- version: '1.1.0',
14
+ version: '1.3.0',
15
15
  data: encrypt(JSON.stringify(data), KEY)
16
16
  }
17
17
 
18
- if (yargs.argv.dryRun) {
18
+ if (argv.dryRun) {
19
19
  console.log('dry running locally');
20
20
  console.log(payload);
21
- if (yargs.argv.reveal) {
22
- console.log(data);
21
+ if (argv.reveal) {
22
+ console.log(JSON.stringify(data));
23
23
  }
24
24
  process.exit();
25
25
  }
26
26
 
27
+ if (!HOME_URL || !KEY) {
28
+ console.log('Missing Phone Home URL or Key.');
29
+ process.exit(1);
30
+ }
31
+
27
32
  axios.post(HOME_URL, payload, {
28
33
  headers: {
29
- 'User-Agent': 'Synetic/ET (NodeJS)'
34
+ 'User-Agent': `Synetic/ET ${payload.version} (NodeJS)`
30
35
  }
31
36
  })
32
37
  .then(() => {
package/lib/collector.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const os = require('os');
3
+ const Redis = require('ioredis');
3
4
 
4
5
  const getLockFilePackages = () => {
5
6
  const lock = getPackageJsonLock();
@@ -28,39 +29,136 @@ const framework = () => {
28
29
  }
29
30
 
30
31
  const getPackageJsonLock = () => {
31
- const packageJson = fs.readFileSync(`${process.cwd()}/package-lock.json`)
32
- return JSON.parse(packageJson);
32
+ try {
33
+ const packageJson = fs.readFileSync(`${process.cwd()}/package-lock.json`)
34
+ return JSON.parse(packageJson);
35
+ } catch (e) {
36
+ return {};
37
+ }
33
38
  }
34
39
  const getPackageJson = () => {
35
- const packageJson = fs.readFileSync(`${process.cwd()}/package.json`)
36
- return JSON.parse(packageJson);
40
+ try {
41
+ const packageJson = fs.readFileSync(`${process.cwd()}/package.json`)
42
+ return JSON.parse(packageJson);
43
+ } catch (e) {
44
+ return { dependencies: {} };
45
+ }
37
46
  }
38
47
 
39
- const data = {
40
- environment: {
41
- version: process.env.APP_ENV || process.env.LAGOON_ENVIRONMENT || process.env.LAGOON_ENVIRONMENT_TYPE || ''
42
- },
43
- engine: {
44
- version: `nodejs ${process.version}`,
45
- },
46
- framework: {
47
- version: framework(),
48
- meta: {
49
- packages: getLockFilePackages(),
48
+ const getRedisInfo = () => {
49
+ return new Promise((resolve) => {
50
+ const host = process.env.REDIS_SERVICE_HOST;
51
+ const port = process.env.REDIS_SERVICE_PORT;
52
+ const password = process.env.REDIS_SERVICE_PASSWORD;
53
+
54
+ if (!host || !port) {
55
+ return resolve(null);
50
56
  }
51
- },
52
- system: {
53
- version: os.release(),
54
- meta: {
55
- identifier: os.hostname(),
56
- ip: '',
57
- uptime: os.uptime(),
58
- cpuCount: os.cpus().length,
59
- load: os.loadavg()
57
+
58
+ const redis = new Redis({
59
+ host: host,
60
+ port: port,
61
+ password: password,
62
+ connectTimeout: 2000,
63
+ maxRetriesPerRequest: 0,
64
+ retryStrategy: () => null // Disable retry
65
+ });
66
+
67
+ redis.info()
68
+ .then((info) => {
69
+ redis.quit();
70
+ resolve(parseRedisInfo(info));
71
+ })
72
+ .catch((err) => {
73
+ redis.quit();
74
+ resolve({ error: err.message });
75
+ });
76
+ });
77
+ };
78
+
79
+ const parseRedisInfo = (infoString) => {
80
+ if (!infoString) return null;
81
+ const lines = infoString.split('\r\n');
82
+
83
+ // Check for Redis error
84
+ if (lines.length > 0 && lines[0].startsWith('-')) {
85
+ return { error: lines[0].substring(1) };
86
+ }
87
+
88
+ const result = {};
89
+ let currentSection = 'default';
90
+
91
+ for (const line of lines) {
92
+ if (line.trim() === '' || line.startsWith('+') || line.startsWith('$') || line.startsWith('*')) continue;
93
+
94
+ if (line.startsWith('#')) {
95
+ currentSection = line.substring(1).trim().toLowerCase();
96
+ result[currentSection] = {};
97
+ continue;
98
+ }
99
+
100
+ const parts = line.split(':');
101
+ if (parts.length === 2) {
102
+ if (!result[currentSection]) {
103
+ result[currentSection] = {};
104
+ }
105
+ result[currentSection][parts[0]] = parts[1].trim();
60
106
  }
61
107
  }
62
- }
108
+ return result;
109
+ };
110
+
111
+ const collect = async () => {
112
+ const redisInfo = await getRedisInfo();
113
+
114
+ const services = {};
115
+ if (redisInfo) {
116
+ let version = '';
117
+ if (redisInfo.server && redisInfo.server.redis_version) {
118
+ version = redisInfo.server.redis_version;
119
+ }
120
+
121
+ let type = 'redis';
122
+ if (redisInfo.server && redisInfo.server.server_name === 'valkey') {
123
+ type = 'valkey';
124
+ }
125
+
126
+ services.redis = {
127
+ type: type,
128
+ version: version,
129
+ meta: redisInfo
130
+ };
131
+ }
132
+
133
+ const data = {
134
+ environment: {
135
+ version: process.env.APP_ENV || process.env.LAGOON_ENVIRONMENT || process.env.LAGOON_ENVIRONMENT_TYPE || ''
136
+ },
137
+ engine: {
138
+ version: `nodejs ${process.version}`,
139
+ },
140
+ framework: {
141
+ version: framework(),
142
+ meta: {
143
+ packages: getLockFilePackages(),
144
+ }
145
+ },
146
+ system: {
147
+ version: os.release(),
148
+ meta: {
149
+ identifier: os.hostname(),
150
+ ip: '',
151
+ uptime: os.uptime(),
152
+ cpuCount: os.cpus().length,
153
+ load: os.loadavg()
154
+ }
155
+ },
156
+ services: services
157
+ };
158
+
159
+ return data;
160
+ };
63
161
 
64
162
  module.exports = {
65
- collect: () => data,
163
+ collect,
66
164
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synetic/et",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "The Synetic ET collector for NodeJs",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,8 @@
15
15
  "npm": ">=6"
16
16
  },
17
17
  "dependencies": {
18
- "axios": "^0.27.2",
19
- "yargs": "^17.5.1"
18
+ "axios": "^1.0.0",
19
+ "ioredis": "^5.9.3",
20
+ "yargs": "^18.0.0"
20
21
  }
21
22
  }
@@ -1,131 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="ForgottenDebugOutputInspection" enabled="true" level="ERROR" enabled_by_default="true">
5
- <option name="configuration">
6
- <list>
7
- <option value="\Codeception\Util\Debug::debug" />
8
- <option value="\Codeception\Util\Debug::pause" />
9
- <option value="\Doctrine\Common\Util\Debug::dump" />
10
- <option value="\Doctrine\Common\Util\Debug::export" />
11
- <option value="\Illuminate\Support\Debug\Dumper::dump" />
12
- <option value="\Symfony\Component\Debug\Debug::enable" />
13
- <option value="\Symfony\Component\Debug\DebugClassLoader::enable" />
14
- <option value="\Symfony\Component\Debug\ErrorHandler::register" />
15
- <option value="\Symfony\Component\Debug\ExceptionHandler::register" />
16
- <option value="\TYPO3\CMS\Core\Utility\DebugUtility::debug" />
17
- <option value="\Zend\Debug\Debug::dump" />
18
- <option value="\Zend\Di\Display\Console::export" />
19
- <option value="dd" />
20
- <option value="debug_print_backtrace" />
21
- <option value="debug_zval_dump" />
22
- <option value="dpm" />
23
- <option value="dpq" />
24
- <option value="dsm" />
25
- <option value="dump" />
26
- <option value="dvm" />
27
- <option value="error_log" />
28
- <option value="kpr" />
29
- <option value="phpinfo" />
30
- <option value="print_r" />
31
- <option value="var_dump" />
32
- <option value="var_export" />
33
- <option value="wp_die" />
34
- <option value="xdebug_break" />
35
- <option value="xdebug_call_class" />
36
- <option value="xdebug_call_file" />
37
- <option value="xdebug_call_function" />
38
- <option value="xdebug_call_line" />
39
- <option value="xdebug_code_coverage_started" />
40
- <option value="xdebug_debug_zval" />
41
- <option value="xdebug_debug_zval_stdout" />
42
- <option value="xdebug_dump_superglobals" />
43
- <option value="xdebug_enable" />
44
- <option value="xdebug_get_code_coverage" />
45
- <option value="xdebug_get_collected_errors" />
46
- <option value="xdebug_get_declared_vars" />
47
- <option value="xdebug_get_function_stack" />
48
- <option value="xdebug_get_headers" />
49
- <option value="xdebug_get_monitored_functions" />
50
- <option value="xdebug_get_profiler_filename" />
51
- <option value="xdebug_get_stack_depth" />
52
- <option value="xdebug_get_tracefile_name" />
53
- <option value="xdebug_is_enabled" />
54
- <option value="xdebug_memory_usage" />
55
- <option value="xdebug_peak_memory_usage" />
56
- <option value="xdebug_print_function_stack" />
57
- <option value="xdebug_start_code_coverage" />
58
- <option value="xdebug_start_error_collection" />
59
- <option value="xdebug_start_function_monitor" />
60
- <option value="xdebug_start_trace" />
61
- <option value="xdebug_stop_code_coverage" />
62
- <option value="xdebug_stop_error_collection" />
63
- <option value="xdebug_stop_function_monitor" />
64
- <option value="xdebug_stop_trace" />
65
- <option value="xdebug_time_index" />
66
- <option value="xdebug_var_dump" />
67
- </list>
68
- </option>
69
- <option name="migratedIntoUserSpace" value="true" />
70
- </inspection_tool>
71
- <inspection_tool class="PhpFullyQualifiedNameUsageInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
72
- <option name="IGNORE_GLOBAL_NAMESPACE" value="true" />
73
- </inspection_tool>
74
- <inspection_tool class="PhpMissingStrictTypesDeclarationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
75
- <inspection_tool class="SecurityAdvisoriesInspection" enabled="true" level="WARNING" enabled_by_default="true">
76
- <option name="optionConfiguration">
77
- <list>
78
- <option value="barryvdh/laravel-debugbar" />
79
- <option value="behat/behat" />
80
- <option value="brianium/paratest" />
81
- <option value="codeception/codeception" />
82
- <option value="codedungeon/phpunit-result-printer" />
83
- <option value="composer/composer" />
84
- <option value="doctrine/coding-standard" />
85
- <option value="filp/whoops" />
86
- <option value="friendsofphp/php-cs-fixer" />
87
- <option value="humbug/humbug" />
88
- <option value="infection/infection" />
89
- <option value="jakub-onderka/php-parallel-lint" />
90
- <option value="johnkary/phpunit-speedtrap" />
91
- <option value="kalessil/production-dependencies-guard" />
92
- <option value="mikey179/vfsStream" />
93
- <option value="mockery/mockery" />
94
- <option value="mybuilder/phpunit-accelerator" />
95
- <option value="orchestra/testbench" />
96
- <option value="pdepend/pdepend" />
97
- <option value="phan/phan" />
98
- <option value="phing/phing" />
99
- <option value="phpcompatibility/php-compatibility" />
100
- <option value="phpmd/phpmd" />
101
- <option value="phpro/grumphp" />
102
- <option value="phpspec/phpspec" />
103
- <option value="phpspec/prophecy" />
104
- <option value="phpstan/phpstan" />
105
- <option value="phpunit/phpunit" />
106
- <option value="povils/phpmnd" />
107
- <option value="roave/security-advisories" />
108
- <option value="satooshi/php-coveralls" />
109
- <option value="sebastian/phpcpd" />
110
- <option value="slevomat/coding-standard" />
111
- <option value="spatie/phpunit-watcher" />
112
- <option value="squizlabs/php_codesniffer" />
113
- <option value="sstalle/php7cc" />
114
- <option value="symfony/debug" />
115
- <option value="symfony/maker-bundle" />
116
- <option value="symfony/phpunit-bridge" />
117
- <option value="symfony/var-dumper" />
118
- <option value="vimeo/psalm" />
119
- <option value="wimg/php-compatibility" />
120
- <option value="wp-coding-standards/wpcs" />
121
- <option value="yiisoft/yii2-coding-standards" />
122
- <option value="yiisoft/yii2-debug" />
123
- <option value="yiisoft/yii2-gii" />
124
- <option value="zendframework/zend-coding-standard" />
125
- <option value="zendframework/zend-debug" />
126
- <option value="zendframework/zend-test" />
127
- </list>
128
- </option>
129
- </inspection_tool>
130
- </profile>
131
- </component>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptLibraryMappings">
4
- <includedPredefinedLibrary name="Node.js Core" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/node.iml" filepath="$PROJECT_DIR$/.idea/node.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/node.iml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$" />
5
- <orderEntry type="inheritedJdk" />
6
- <orderEntry type="sourceFolder" forTests="false" />
7
- </component>
8
- </module>
package/.idea/vcs.xml DELETED
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="CommitMessageInspectionProfile">
4
- <profile version="1.0">
5
- <inspection_tool class="CommitFormat" enabled="true" level="WARNING" enabled_by_default="true" />
6
- <inspection_tool class="CommitNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
7
- </profile>
8
- </component>
9
- <component name="VcsDirectoryMappings">
10
- <mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
11
- </component>
12
- </project>