Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add statuspage engine auto-detection
- Loading branch information
1 parent
c9c2aa3
commit 21fc622
Showing
8 changed files
with
159 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/go-resty/resty/v2" | ||
"go.uber.org/zap" | ||
|
||
"github.com/sergeyshevch/statuspage-exporter/pkg/config" | ||
"github.com/sergeyshevch/statuspage-exporter/pkg/statusio" | ||
"github.com/sergeyshevch/statuspage-exporter/pkg/statuspageio" | ||
) | ||
|
||
// DetectStatusPageType detects statuspage engine for all configured statuspage URLs. | ||
func DetectStatusPageType(log *zap.Logger, restyClient *resty.Client) ([]string, []string) { | ||
targetUrls := config.StatusPages() | ||
|
||
var statusPageIoPages, statusIoPages []string | ||
|
||
for _, targetURL := range targetUrls { | ||
if statuspageio.IsStatusPageIOPage(log, targetURL, restyClient) { | ||
log.Info("Detected StatusPage.io page", zap.String("url", targetURL)) | ||
statusPageIoPages = append(statusPageIoPages, targetURL) | ||
} else if statusio.IsStatusIOPage(log, targetURL, restyClient) { | ||
log.Info("Detected Status.io page", zap.String("url", targetURL)) | ||
statusIoPages = append(statusIoPages, targetURL) | ||
} | ||
} | ||
|
||
return statusPageIoPages, statusIoPages | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"time" | ||
|
||
"github.com/go-resty/resty/v2" | ||
"go.uber.org/zap" | ||
|
||
"github.com/sergeyshevch/statuspage-exporter/pkg/config" | ||
) | ||
|
||
// StartFetchingLoop starts a loop that fetches status pages. | ||
func StartFetchingLoop(ctx context.Context, wg *sync.WaitGroup, | ||
log *zap.Logger, client *resty.Client, targetURLs []string, | ||
fetcher func(*zap.Logger, *resty.Client, []string), | ||
) { | ||
wg.Add(1) | ||
defer wg.Done() | ||
|
||
fetchDelay := config.FetchDelay() | ||
|
||
for { | ||
select { | ||
default: | ||
fetcher(log, client, targetURLs) | ||
|
||
time.Sleep(fetchDelay) | ||
case <-ctx.Done(): | ||
log.Info("Stopping fetching loop") | ||
|
||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package utils | ||
|
||
import "errors" | ||
|
||
// ErrInvalidURL is returned when URL is invalid. | ||
var ErrInvalidURL = errors.New("invalid URL. It won't be parsed. Check that your url contains scheme") |