diff --git a/.gitignore b/.gitignore index 35f2d43a9..fb5012541 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ node_modules package-lock.json tmp content/telegraf/v1/input-plugins +content/telegraf/v1/output-plugins + diff --git a/build-telegraf/plugins.sh b/build-telegraf/plugins.sh index c04ef11b2..f988fc3b1 100644 --- a/build-telegraf/plugins.sh +++ b/build-telegraf/plugins.sh @@ -3,38 +3,23 @@ # Determine the root project directory ROOT_DIR=$(git rev-parse --show-toplevel) -# Clone an external repository -git clone https://github.com/influxdata/telegraf.git "$ROOT_DIR/external/telegraf" +# If the Telegraf repo isn't already cloned in ./external, clone it +if [ ! -d "$ROOT_DIR/external/telegraf" ]; then + git clone https://github.com/influxdata/telegraf.git "$ROOT_DIR/external/telegraf" +fi # Update the external repository cd "$ROOT_DIR/external/telegraf" git pull origin master # Function to create a Hugo page create_page() { - local plugin_dir=$1 - local dest_dir=$2 + local dest_dir=$1 local dest_file="$dest_dir/_index.md" - local parent=$3 + local content=$2 - # Check if the plugin directory exists - if [ -d "$plugin_dir" ]; then - mkdir -p "$dest_dir" - # Use a heredoc to write the frontmatter to the destination file - cat < "$dest_file" ---- -description: "Telegraf plugin for collecting metrics from $plugin_dir" -menu: - telegraf_v1_ref: - parent: $parent - name: $(basename "$plugin_dir") -tags: [$(basename "$plugin_dir")] ---- - -EOF - else - echo "Plugin directory not found: $plugin_dir" - fi + mkdir -p "$dest_dir" + echo "$content" > "$dest_file" } # Function to copy README.md content to _index.md @@ -56,7 +41,7 @@ copy_readme() { fi # Copy the README.md content to _index.md - cat $src_readme >> $dest_file + cat "$src_readme" >> "$dest_file" echo "Copied $src_readme to $dest_file" } @@ -69,39 +54,72 @@ semaphore() { } # Limit the number of concurrent processes -MAX_CONCURRENT=10 +MAX_CONCURRENT=5 -build() { - # For each plugin in external/telegraf/plugins/inputs, - # copy the README.md file to content. - local input_plugins_dir="$ROOT_DIR/content/telegraf/v1/input-plugins" - cat < "$input_plugins_dir/_index.md" +# Function to generate frontmatter for input plugins +input_plugin_frontmatter() { + local plugin_name=$1 + + cat < "$dest_dir/_index.md" + + for plugin_dir in "$src_dir"/*; do + # If the directory name is "all", then skip it + if [ "$(basename "$plugin_dir")" == "all" ]; then + continue + fi + local plugin_name=$(basename "$plugin_dir") + local plugin_dest_dir=$dest_dir/$plugin_name if [ -d "$plugin_dir" ]; then - # If the directory name is "all", then skip it - if [ "$(basename "$plugin_dir")" == "all" ]; then - continue - fi - local plugin_name=$(basename "$plugin_dir") - local dest_dir=$input_plugins_dir/$plugin_name semaphore "$MAX_CONCURRENT" ( - create_page "$plugin_dir" "$dest_dir" "Input Plugins" - copy_readme "$plugin_dir" "$dest_dir" - ) & + local frontmatter=$($frontmatter_func "$plugin_name") + create_page "$plugin_dest_dir" "$frontmatter" + copy_readme "$plugin_dir" "$plugin_dest_dir" + ) & fi done @@ -109,4 +127,54 @@ EOF wait } -build +# Configuration for input plugins +SRC_DIR_INPUT="$ROOT_DIR/external/telegraf/plugins/inputs" +DEST_DIR_INPUT="$ROOT_DIR/content/telegraf/v1/input-plugins" +FRONTMATTER_FUNC_INPUT="input_plugin_frontmatter" +MAIN_FRONTMATTER_INPUT=$(cat <}} + +EOF +) + +# Run the build function for input plugins +build "$SRC_DIR_INPUT" "$DEST_DIR_INPUT" "$FRONTMATTER_FUNC_INPUT" "$MAIN_FRONTMATTER_INPUT" + +# Configuration for output plugins +SRC_DIR_OUTPUT="$ROOT_DIR/external/telegraf/plugins/outputs" +DEST_DIR_OUTPUT="$ROOT_DIR/content/telegraf/v1/output-plugins" +FRONTMATTER_FUNC_OUTPUT="output_plugin_frontmatter" +MAIN_FRONTMATTER_OUTPUT=$(cat <}} + +EOF +) + +# Run the build function for output plugins +build "$SRC_DIR_OUTPUT" "$DEST_DIR_OUTPUT" "$FRONTMATTER_FUNC_OUTPUT" "$MAIN_FRONTMATTER_OUTPUT" \ No newline at end of file