{"id":20236867,"url":"https://github.com/uniwue-rz/icinga2-api","last_synced_at":"2025-08-26T08:08:08.586Z","repository":{"id":62538763,"uuid":"114739013","full_name":"uniwue-rz/icinga2-api","owner":"uniwue-rz","description":"Icinga2 API client written in PHP (Mirror only here)","archived":false,"fork":false,"pushed_at":"2020-04-04T22:35:47.000Z","size":504,"stargazers_count":3,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-21T11:50:39.283Z","etag":null,"topics":["icinga2-api","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uniwue-rz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-19T08:28:09.000Z","updated_at":"2022-10-28T19:53:20.000Z","dependencies_parsed_at":"2022-11-02T15:30:31.296Z","dependency_job_id":null,"html_url":"https://github.com/uniwue-rz/icinga2-api","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uniwue-rz%2Ficinga2-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uniwue-rz%2Ficinga2-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uniwue-rz%2Ficinga2-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uniwue-rz%2Ficinga2-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uniwue-rz","download_url":"https://codeload.github.com/uniwue-rz/icinga2-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224589085,"owners_count":17336409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["icinga2-api","php"],"created_at":"2024-11-14T08:23:37.895Z","updated_at":"2024-11-14T08:23:38.488Z","avatar_url":"https://github.com/uniwue-rz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Icinga2 Api Client for PHP\n\nThis is a simple api client for Icinga2 written in PHP. At the moment it has only\nread functions. In the future it will be capable of writing to Icinga2\ntoo.\n\n## Installation\n\nTo use this client simply add it to your package requirements with composer:\n\n```lang=bash\ncomposer require rzuw/icinga2\n```\n\n## Configuration for Client\n\nThe following settings should be set to make this client work. \n\n```lang=php\n$config = array\n(\n    \"host\" =\u003e \"\"\n    \"port\" =\u003e \"\"\n    // should be set when you decide for username and password login\n    \"user\" =\u003e \"\"\n    \"password\" =\u003e \"\"\n    // should be used when you decide for certificate login\n    \"cert\" =\u003e \"\"\n    \"key\" =\u003e \"\"\n);\n```\n\n## Configuration for Icinga2 Backend\n\nThe complete configuration for API settings for an Icinga2 backend is available\nin [Icinga2 Documentation](https://www.icinga.com/docs/icinga2/latest/doc/12-icinga2-api/). There will be to example for API configuration available\none for Authentication with username and password, the other using a X509 certificate.\n\n## Configure API\n\nTo configure the Api settings you need to create the master certificates:\n\n```lang=bash\nicinga2 pki new-ca\ncd /var/lib/icinga2/certs/\nicinga2 pki new-cert --cn your-master-instance-fqdn --csr your-master-instance-fqdn.csr --key your-master-instance-fqdn.key\nicinga2 pki sign-csr --csr your-master-instance-fqdn.csr --cert your-master-instance-fqdn.crt\n```\n\nCopy the `ca.crt` to your client you will need this for your future authentications.\n\nThen add the following configuration for the API, in `/etc/icinga2/features-available/api.conf`\n\n```lang=conf\n/**\n * The API listener is used for distributed monitoring setups.\n */\nobject ApiListener \"api\" {\n accept_commands = true\n accept_config = true\n ticket_salt = TicketSalt\n}\n```\n\nEnable the Api settings with commandline or creating a link:\n\n```lang=bash\n# Using Commandline\nicinga2 feature eanble api\n# Or Using link\nln -s /etc/icinga2/features-available/api.conf /etc/icinga2/features-enabled/api.conf\n```\n\n### Using Username and Password\n\nIn `/etc/icinga2/conf.d/api-users.conf` add your new user with the given settings:\n\n```lang=config\nobject ApiUser \"your-user\"{\n  password = \"your-password\"\n  permissions = [\"*\"]\n}\n```\n\nTo test the settings use curl:\n\n```lang=bash\ncurl -u your-user:your-password --cacert ca.crt 'https://your-icinga2-domain:5665/v1'\n```\n\n### Using X509 Certificate\n\nIt is possible to use Icinga2 Api with certificates, to do this you need to create the needed\nca certificate, a client certificate and then sign the certificate with ca. The complete documentation can\nbe found on [Icinga2 website](https://www.icinga.com/docs/icinga2/latest/doc/06-distributed-monitoring/#manual-certificate-creation).\n\n\n```lang=bash\ncd /var/lib/icinga2/certs/\nicinga2 pki new-cert --cn your-client-cn --csr your-client-cn.csr --key your-client-cn.key\nicinga2 pki sign-csr --csr your-client-cn.csr --cert your-client-cn.crt\n```\n\nIn `/etc/icinga2/conf.d/api-users.conf` add your new user with the given settings:\n\n```lang=config\nobject ApiUser \"your-client-user\"{\n  client_cn = \"your-client-cn\"\n  permissions = [\"*\"]\n}\n```\n\nRestart the Icinga2 Daemon:\n\n```lang=bash\nsystemctl restart icinga2\n```\n\nCopy `your-client-cn.crt` and `your-client-cn.key` to your Api client and\nthey can be used.\n\nTo test the clients simply use the following `curl` command:\n\n```lang=bash\ncurl --cert your-client-cn.crt --key your-client-cn.key --cacert ca.crt 'https://your-icinga-api-domain:5665/v1'\n# On Successful attempt you will see:\n# \u003chtml\u003e\u003chead\u003e\u003ctitle\u003eIcinga 2\u003c/title\u003e\u003c/head\u003e\u003ch1\u003eHello from Icinga 2 (Version: r2.8.0-1)!\u003c/h1\u003e\u003cp\u003eYou are authenticated as \u003cb\u003eyour-client-user\u003c/b\u003e. Your user has the following permissions:\u003c/p\u003e \u003cul\u003e\u003cli\u003e*\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eMore information about API requests is available in the \u003ca href=\"https://docs.icinga.com/icinga2/latest\" target=\"_blank\"\u003edocumentation\u003c/a\u003e.\u003c/p\u003e\u003c/html\u003e\n```\n\n## Usage\n\nTo use this client simply create an instance of Icinga2Api class and\nload the configuration inside.\n\n```lang=php\n$config = array\n(\n    \"host\" =\u003e \"\"\n    \"port\" =\u003e \"\"\n    // should be set when you decide for username and password login\n    \"user\" =\u003e \"\"\n    \"password\" =\u003e \"\"\n    // should be used when you decide for certificate login\n    \"cert\" =\u003e \"\"\n    \"key\" =\u003e \"\"\n);\n$icinga2 = new Icinga2($config);\n$matchedHosts = $icinga2-\u003egetHosts(array(\"match(\\\"\" . $this-\u003ehostData[\"hostname\"] . \"*\\\",host.name)\"\n```\n\nSee the test cases for more examples.\n\n## Testing\n\nTo test this client you need to have `phpunit` installed. And the following\nenvironmental variables should be set.\n\n```lang=bash\nexport ICINGA2HOST=\"Your API HOST\"\nexport ICINGA2PORT=\"YOUR API PORT\"\nexport ICINGA2USERNAME= \"\"\nexport ICINGA2PASSWORD=\"\"\nexport ICINGA2CERTPATH=\"\"\nexport ICINGA2KEYPATH=\"\"\nexport ICINGA2CAPATH=\"\"\nexport ICINGA2KEYPASSWORD=\"\"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funiwue-rz%2Ficinga2-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funiwue-rz%2Ficinga2-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funiwue-rz%2Ficinga2-api/lists"}