{"id":28931502,"url":"https://github.com/ridvanaltun/cortex-php-sdk","last_synced_at":"2026-06-29T06:31:33.237Z","repository":{"id":62535777,"uuid":"265855653","full_name":"ridvanaltun/cortex-php-sdk","owner":"ridvanaltun","description":"API client for Cortex.","archived":false,"fork":false,"pushed_at":"2020-05-21T13:41:21.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-27T15:34:40.698Z","etag":null,"topics":["cortex","prometheus"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ridvanaltun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-21T13:28:17.000Z","updated_at":"2020-05-24T00:29:35.000Z","dependencies_parsed_at":"2022-11-02T15:00:55.783Z","dependency_job_id":null,"html_url":"https://github.com/ridvanaltun/cortex-php-sdk","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ridvanaltun/cortex-php-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridvanaltun%2Fcortex-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridvanaltun%2Fcortex-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridvanaltun%2Fcortex-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridvanaltun%2Fcortex-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ridvanaltun","download_url":"https://codeload.github.com/ridvanaltun/cortex-php-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridvanaltun%2Fcortex-php-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34916409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cortex","prometheus"],"created_at":"2025-06-22T16:06:24.574Z","updated_at":"2026-06-29T06:31:33.207Z","avatar_url":"https://github.com/ridvanaltun.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Cortex SDK\n\n\u003e Manage [Cortex](https://github.com/cortexproject/cortex).\n\n# Table of Contents\n\n- [PHP Cortex SDK](#php-cortex-sdk)\n- [Table of Contents](#table-of-contents)\n- [Installation](#installation)\n- [Usage](#usage)\n\n# Installation\n\n```bash\n$ composer require ridvanaltun/cortex\n```\n\n# Usage\n\n```php\nuse ridvanaltun\\Cortex\\Cortex;\nuse ridvanaltun\\Cortex\\Exceptions\\RuleExist;\nuse ridvanaltun\\Cortex\\Exceptions\\RuleNotExist;\nuse ridvanaltun\\Cortex\\Exceptions\\TemplateExist;\nuse ridvanaltun\\Cortex\\Exceptions\\TemplateNotExist;\nuse ridvanaltun\\Cortex\\Exceptions\\UnknownRuleFormatVersion;\nuse ridvanaltun\\Cortex\\Exceptions\\AlertmanagerConfigNotOk;\nuse ridvanaltun\\Cortex\\Exceptions\\AlertmanagerConfigNotExist;\n\n$host = 'http://localhost:9002';\n$username = 'username';\n$password = 'password';\n\n$cortex = new Cortex($host, $username, $password, [\n    'timeout' =\u003e 5,\n    'verify'  =\u003e false, // don't verify ssl\n]);\n\n$consumer = 'consumer';\n$configsService = $cortex-\u003econfigsService($consumer);\n\ntry {\n\n    # list all alertmanager configs (all tenants)\n    $allConfigs = $cortex-\u003elistAllAlertmanagerConfigs();\n    var_dump($allConfigs);\n\n    # list tenant rules\n    $rules = $configsService-\u003egetRuleFiles();\n    var_dump($rules);\n\n    # add a rule file for tenant\n    $configsService-\u003eaddRuleFile('filename', [\n      [\n        'alert' =\u003e 'alertname1',\n        'for' =\u003e'10m',\n        'expr' =\u003e 'up == 0',\n      ],\n      [\n        'alert' =\u003e 'alertname2',\n        'for' =\u003e'15m',\n        'expr' =\u003e 'up == 1',\n        'labels' =\u003e [\n          'severity' =\u003e 'page',\n        ],\n        'annotations' =\u003e [\n          'summary' =\u003e 'High request latency',\n        ],\n      ]\n    ]);\n\n    # add or replace rule file for tenant\n    $configsService-\u003eapplyRuleFile('filename', [\n      [\n        'alert' =\u003e 'alertname4',\n        'for' =\u003e'10m',\n        'expr' =\u003e 'up == 0',\n      ],\n      [\n        'alert' =\u003e 'alertname2',\n        'for' =\u003e'15m',\n        'expr' =\u003e 'up == 1',\n        'labels' =\u003e [],\n        'annotations' =\u003e [],\n      ]\n    ]);\n\n    # remove rule for tenant\n    $configsService-\u003eremoveRuleFile('rulename');\n\n    # remove all rules for tenant\n    $configsService-\u003eremoveAllRuleFiles();\n\n    # change rule format version for tenant, can be set 1 or 2\n    $configsService-\u003echangeRuleFormatVersion('2');\n\n    # list tenant templates\n    $templates = $configsService-\u003egetTemplateFiles();\n    var_dump($templates);\n\n    # add a template file for tenant\n    $template = '{{ define \"slack.myorg.text\" }}https://internal.myorg.net/wiki/alerts/{{ .GroupLabels.app }}/{{ . GroupLabels.alertname }}{{ end}}';\n    $configsService-\u003eaddTemplateFile('filename', $template);\n\n    # add or replace template file for tenant\n    $template = '{{ define \"slack.myorg.text\" }}https://internal.myorg.net/wiki/alerts/{{ . GroupLabels.app }}/{{ .GroupLabels.alertname }}{{ end}}';\n    $configsService-\u003eapplyTemplateFile('filename', $template);\n\n    # remove template for tenant\n    $configsService-\u003eremovTemplateFile('templatename');\n\n    # remove all templates for tenant\n    $configsService-\u003eremoveAllTemplateFiles();\n\n    # get tenant alertmanager config\n    $alertmanager = $configsService-\u003egetAlertmanagerConfig();\n    var_dump($alertmanager);\n\n    # remove tenant alertmanager config\n    $configsService-\u003eremoveAlertmanagerConfig();\n\n    # replace tenant alertmanager config\n    $configsService-\u003ereplaceAlertmanagerConfig([\n      'global' =\u003e [\n        'smtp_smarthost' =\u003e 'localhost:25',\n        'smtp_from' =\u003e 'alertmanager@example.org',\n        'smtp_auth_username' =\u003e 'alertmanager',\n        'smtp_auth_password' =\u003e 'password',\n      ],\n      'route' =\u003e [\n        'receiver' =\u003e 'team-X-mails',\n      ],\n      'receivers' =\u003e [\n        [\n          'name' =\u003e 'team-X-mails',\n          'email_configs' =\u003e [\n            [\n              'to' =\u003e 'abc@domain.com',\n            ],\n          ],\n        ],\n      ],\n    ]);\n\n    # remove alertmanager config for tenant\n    $configsService-\u003eremoveAlertmanagerConfig();\n\n    # validate alertmanager config\n    $cortex-\u003evalidateAlertmanagerConfig([\n      'global' =\u003e [\n        'smtp_smarthost' =\u003e 'localhost:25',\n        'smtp_from' =\u003e 'alertmanager@example.org',\n        'smtp_auth_username' =\u003e 'alertmanager',\n        'smtp_auth_password' =\u003e 'password',\n      ],\n      'route' =\u003e [\n        'receiver' =\u003e 'team-X-mails',\n      ],\n      'receivers' =\u003e [\n        [\n          'name' =\u003e 'team-X-mails',\n          'email_configs' =\u003e [\n            [\n              'to' =\u003e 'abc@domain.com',\n            ],\n          ],\n        ],\n      ],\n    ]);\n\n    # deactive alerting for tenant\n    $configsService-\u003edeactivate();\n\n    # activate alerting for tenant\n    $configsService-\u003eactivate();\n\n} catch (AlertmanagerConfigNotOk $e) {\n    echo \"Provided config not ok.\";\n} catch (RuleExist $e) {\n    echo \"Rule already exist.\";\n} catch (RuleNotExist $e) {\n    echo \"Rule not exist.\";\n} catch (TemplateExist $e) {\n    echo \"Template already exist.\";\n} catch (TemplateNotExist $e) {\n    echo \"Template not exist.\";\n} catch (AlertmanagerConfigNotExist $e) {\n    echo \"Alertmanager config not exist.\";\n} catch (UnknownRuleFormatVersion $e) {\n    echo \"Unknown rule format version.\";\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridvanaltun%2Fcortex-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fridvanaltun%2Fcortex-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridvanaltun%2Fcortex-php-sdk/lists"}