Skip to content

Commit 6ab94d9

Browse files
authored
Merge pull request #718 from intel/push-2024-04-12
Push 2024 04 12
2 parents 6a27239 + 18b90a0 commit 6ab94d9

File tree

5 files changed

+93
-45
lines changed

5 files changed

+93
-45
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
# Initializes the CodeQL tools for scanning.
5252
- name: Initialize CodeQL
53-
uses: github/codeql-action/init@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
53+
uses: github/codeql-action/init@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
5454
with:
5555
languages: ${{ matrix.language }}
5656
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -60,7 +60,7 @@ jobs:
6060
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
6161
# If this step fails, then you should remove it and run the build manually (see below)
6262
- name: Autobuild
63-
uses: github/codeql-action/autobuild@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
63+
uses: github/codeql-action/autobuild@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
6464

6565
# ℹ️ Command-line programs to run using the OS shell.
6666
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -73,6 +73,6 @@ jobs:
7373
# ./location_of_script_within_repo/buildscript.sh
7474

7575
- name: Perform CodeQL Analysis
76-
uses: github/codeql-action/analyze@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
76+
uses: github/codeql-action/analyze@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
7777
with:
7878
category: "/language:${{matrix.language}}"

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ jobs:
7373

7474
# Upload the results to GitHub's code scanning dashboard.
7575
- name: "Upload to code-scanning"
76-
uses: github/codeql-action/upload-sarif@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
76+
uses: github/codeql-action/upload-sarif@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
7777
with:
7878
sarif_file: results.sarif

scripts/grafana/clean.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
rm -rf provisioning/datasources
4+
rm -rf *_volume

scripts/grafana/start-prometheus.sh

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,73 @@
11
#!/bin/sh
22

3-
if [ "$#" -ne 1 ];
4-
then
3+
set -e
4+
5+
usage() {
56
echo
67
echo "Usage: $0 target_address:port"
78
echo
89
echo "target_address is the hostname or IP address of the system that runs pcm-sensor-server"
10+
echo
11+
echo "Alternative usage: $0 filename"
12+
echo
13+
echo "Specify filename containing target_address:port in each line"
914
exit 1
10-
fi
15+
}
1116

12-
CTR_RUN=${CTR_RUN:-docker}
17+
# Validate the URL format and reject localhost or 127.0.0.1
18+
validate_url() {
19+
local url=$1
20+
local regex='^([a-zA-Z0-9.-]+):[0-9]+$'
21+
local localhost_regex='^(localhost|127\.0\.0\.1):[0-9]+$'
1322

14-
mkdir -p grafana_volume/dashboards
15-
mkdir -p prometheus_volume
23+
if ! [[ $url =~ $regex ]]; then
24+
echo "Error: The target_address ($url) provided is not in the correct format."
25+
usage
26+
fi
1627

17-
chmod -R 777 *_volume
28+
if [[ $url =~ $localhost_regex ]]; then
29+
echo "Error: The target_address cannot be localhost or 127.0.0.1."
30+
usage
31+
fi
32+
}
1833

19-
mkdir -p provisioning/datasources
20-
cp automatic_prometheus.yml provisioning/datasources/automatic.yml
34+
if [ "$#" -ne 1 ]; then
35+
usage
36+
fi
2137

38+
CTR_RUN=${CTR_RUN:-docker}
39+
40+
mkdir -p grafana_volume/dashboards || { echo "Error creating grafana_volume/dashboards directory"; exit 1; }
41+
mkdir -p prometheus_volume || { echo "Error creating prometheus_volume directory"; exit 1; }
42+
43+
chmod -R 777 *_volume || { echo "Error setting permissions on volume directories"; exit 1; }
2244

45+
mkdir -p provisioning/datasources || { echo "Error creating provisioning/datasources directory"; exit 1; }
46+
cp automatic_prometheus.yml provisioning/datasources/automatic.yml || { echo "Error copying automatic_prometheus.yml"; exit 1; }
2347

2448
# check if argument is file, create the prometheus.yml accordingly
2549
if [ -f "$1" ]; then
2650
echo "creating prometheus.yml for hosts in targets file";
27-
head -n -1 "prometheus.yml.template" > prometheus.yml
51+
head -n -1 "prometheus.yml.template" > prometheus.yml || { echo "Error creating prometheus.yml"; exit 1; }
2852
while read -r line; do
53+
validate_url "$line"
2954
echo " - targets: ['$line']" >> "prometheus.yml"
3055
done < "$1"
3156
echo Downloading PCM dashboard
32-
curl -o grafana_volume/dashboards/pcm-dashboard.json $(head -1 $1)/dashboard/prometheus
33-
57+
curl -o grafana_volume/dashboards/pcm-dashboard.json $(head -1 "$1")/dashboard/prometheus || { echo "Error downloading PCM dashboard"; exit 1; }
3458
else
59+
validate_url "$1"
3560
echo "creating prometheus.yml for $1 ";
36-
sed "s#PCMSENSORSERVER#$1#g" prometheus.yml.template > prometheus.yml
61+
sed "s#PCMSENSORSERVER#$1#g" prometheus.yml.template > prometheus.yml || { echo "Error creating prometheus.yml"; exit 1; }
3762
echo Downloading PCM dashboard
38-
curl -o grafana_volume/dashboards/pcm-dashboard.json $1/dashboard/prometheus
63+
curl -o grafana_volume/dashboards/pcm-dashboard.json "$1"/dashboard/prometheus || { echo "Error downloading PCM dashboard"; exit 1; }
3964
fi
4065

4166
echo "Starting prometheus network"
42-
${CTR_RUN} network create prometheus-network
67+
${CTR_RUN} network create prometheus-network || { echo "Error creating prometheus network"; exit 1; }
4368
echo Starting prometheus
44-
${CTR_RUN} run --name prometheus --network=prometheus-network -d -p 9090:9090 -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml:Z -v $PWD/prometheus_volume:/prometheus:Z quay.io/prometheus/prometheus:latest
69+
${CTR_RUN} run --name prometheus --network=prometheus-network -d -p 9090:9090 -v "$PWD"/prometheus.yml:/etc/prometheus/prometheus.yml:Z -v "$PWD"/prometheus_volume:/prometheus:Z quay.io/prometheus/prometheus:latest || { echo "Error starting prometheus"; exit 1; }
4570
echo Starting grafana
46-
${CTR_RUN} run -d --network=prometheus-network --name=grafana -p 3000:3000 -v $PWD/grafana_volume:/var/lib/grafana:Z -v $PWD/provisioning:/etc/grafana/provisioning:Z docker.io/grafana/grafana:latest
47-
48-
echo Start browser at http://localhost:3000/ and login with admin user, password admin
71+
${CTR_RUN} run -d --network=prometheus-network --name=grafana -p 3000:3000 -v "$PWD"/grafana_volume:/var/lib/grafana:Z -v "$PWD"/provisioning:/etc/grafana/provisioning:Z docker.io/grafana/grafana:latest || { echo "Error starting grafana"; exit 1; }
4972

73+
echo "Start browser at http://"`hostname`":3000/ or http://localhost:3000/ and login with admin user, password admin"

scripts/grafana/start.sh

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,77 @@
11
#!/bin/sh
22

3-
if [ "$#" -ne 1 ];
4-
then
3+
set -e
4+
5+
usage() {
56
echo
67
echo "Usage: $0 http(s)://target_address:port"
78
echo
89
echo "target_address is the hostname or IP address of the system that runs pcm-sensor-server"
910
exit 1
10-
fi
11+
}
12+
13+
# Validate the URL format and reject localhost or 127.0.0.1
14+
validate_url() {
15+
local url=$1
16+
local regex='^https?://([a-zA-Z0-9.-]+):[0-9]+$'
17+
local localhost_regex='^(https?://)?(localhost|127\.0\.0\.1):[0-9]+$'
18+
19+
if ! [[ $url =~ $regex ]]; then
20+
echo "Error: The URL provided is not in the correct format."
21+
usage
22+
fi
1123

24+
if [[ $url =~ $localhost_regex ]]; then
25+
echo "Error: The target_address cannot be localhost or 127.0.0.1."
26+
usage
27+
fi
28+
}
1229

13-
mkdir -p grafana_volume/dashboards
14-
mkdir -p influxdb_volume
30+
if [ "$#" -ne 1 ]; then
31+
usage
32+
fi
33+
34+
validate_url "$1"
1535

16-
chmod -R 777 *_volume
36+
mkdir -p grafana_volume/dashboards || { echo "Error creating grafana_volume/dashboards directory"; exit 1; }
37+
mkdir -p influxdb_volume || { echo "Error creating influxdb_volume directory"; exit 1; }
1738

18-
mkdir -p provisioning/datasources
19-
cp automatic_influxdb.yml provisioning/datasources/automatic.yml
39+
chmod -R 777 *_volume || { echo "Error setting permissions on volume directories"; exit 1; }
2040

41+
mkdir -p provisioning/datasources || { echo "Error creating provisioning/datasources directory"; exit 1; }
42+
cp automatic_influxdb.yml provisioning/datasources/automatic.yml || { echo "Error copying automatic_influxdb.yml"; exit 1; }
2143

2244
CTR_RUN=${CTR_RUN:-docker}
2345

2446
# check if argument is file, create the telegraf.conf accordingly
2547
if [ -f "$1" ]; then
2648
echo "creating telegraf.conf for hosts in targets file";
27-
head -n -7 "telegraf.conf.template" > telegraf.conf
49+
head -n -7 "telegraf.conf.template" > telegraf.conf || { echo "Error creating telegraf.conf"; exit 1; }
2850
while IFS='' read -r line || [[ -n "$line" ]]; do
2951
# Split the line at the : character to get the IP and port
3052
ip=$(echo "$line" | cut -d ':' -f 1)
3153
port=$(echo "$line" | cut -d ':' -f 2)
3254
# Append the transformed line to the output file, separated by a comma
3355
echo -n "\"http://$ip:$port/persecond/\"," >> telegraf.conf
34-
done < $1
35-
sed -i '$ s/,$//' telegraf.conf
36-
tail -n -6 "telegraf.conf.template" >> telegraf.conf
56+
done < "$1"
57+
sed -i '$ s/,$//' telegraf.conf || { echo "Error editing telegraf.conf"; exit 1; }
58+
tail -n -6 "telegraf.conf.template" >> telegraf.conf || { echo "Error appending to telegraf.conf"; exit 1; }
3759
echo Downloading PCM dashboard
38-
curl -o grafana_volume/dashboards/pcm-dashboard.json $(head -1 $1)/dashboard
39-
60+
curl -o grafana_volume/dashboards/pcm-dashboard.json $(head -1 "$1")/dashboard || { echo "Error downloading PCM dashboard"; exit 1; }
4061
else
4162
echo "creating telegraf.conf for $1 ";
42-
sed "s#PCMSENSORSERVER#$1#g" telegraf.conf.template > telegraf.conf
63+
sed "s#PCMSENSORSERVER#$1#g" telegraf.conf.template > telegraf.conf || { echo "Error creating telegraf.conf"; exit 1; }
4364
echo Downloading PCM dashboard
44-
curl -o grafana_volume/dashboards/pcm-dashboard.json $1/dashboard
65+
curl -o grafana_volume/dashboards/pcm-dashboard.json "$1"/dashboard || { echo "Error downloading PCM dashboard"; exit 1; }
4566
fi
4667

4768
echo "Creating influxdb network"
48-
${CTR_RUN} network create influxdb-network
69+
${CTR_RUN} network create influxdb-network || { echo "Error creating influxdb network"; exit 1; }
4970
echo Starting influxdb
50-
${CTR_RUN} run -d --name influxdb -p 8083:8083 -p 8086:8086 --network=influxdb-network -v $PWD/influxdb_volume:/var/lib/influxdb influxdb:1.8.0-alpine
71+
${CTR_RUN} run -d --name influxdb -p 8083:8083 -p 8086:8086 --network=influxdb-network -v "$PWD"/influxdb_volume:/var/lib/influxdb influxdb:1.8.0-alpine || { echo "Error starting influxdb"; exit 1; }
5172
echo Starting telegraf
52-
${CTR_RUN} run -d --name telegraf --network=influxdb-network -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro telegraf
73+
${CTR_RUN} run -d --name telegraf --network=influxdb-network -v "$PWD"/telegraf.conf:/etc/telegraf/telegraf.conf:ro telegraf || { echo "Error starting telegraf"; exit 1; }
5374
echo Starting grafana
54-
${CTR_RUN} run -d --network=influxdb-network --name grafana -p 3000:3000 -v $PWD/provisioning:/etc/grafana/provisioning -v $PWD/grafana_volume:/var/lib/grafana grafana/grafana
55-
56-
echo Start browser at http://localhost:3000/ and login with admin user, password admin
75+
${CTR_RUN} run -d --network=influxdb-network --name grafana -p 3000:3000 -v "$PWD"/provisioning:/etc/grafana/provisioning -v "$PWD"/grafana_volume:/var/lib/grafana grafana/grafana || { echo "Error starting grafana"; exit 1; }
5776

77+
echo "Start browser at http://"`hostname`":3000/ or http://localhost:3000/ and login with admin user, password admin"

0 commit comments

Comments
 (0)