├── .gitignore ├── .mailmap ├── .travis.yml ├── LICENSE ├── README.md ├── build.config.js ├── images ├── pagerduty-notification-1.png ├── pagerduty-notification-2.png └── pagerduty-notification-3.png ├── package.json ├── pom.xml ├── src ├── deb │ └── control │ │ └── control ├── main │ ├── java │ │ └── org │ │ │ └── graylog │ │ │ └── plugins │ │ │ └── pagerduty │ │ │ ├── PagerDutyNotification.java │ │ │ ├── PagerDutyNotificationConfig.java │ │ │ ├── PagerDutyNotificationConfigEntity.java │ │ │ ├── PagerDutyNotificationPluginMetaData.java │ │ │ ├── PagerDutyNotificationPluginModule.java │ │ │ ├── PagerDutyNotificationPluginPlugin.java │ │ │ ├── client │ │ │ ├── ClientFactory.java │ │ │ ├── MessageFactory.java │ │ │ └── PagerDuty.java │ │ │ └── dto │ │ │ ├── Link.java │ │ │ ├── PagerDutyMessage.java │ │ │ └── PagerDutyResponse.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── org.graylog2.plugin.Plugin │ │ └── org.graylog.plugins.graylog-plugin-pagerduty │ │ └── graylog-plugin.properties ├── test │ └── java │ │ └── org │ │ └── graylog │ │ └── plugins │ │ └── pagerduty │ │ ├── PagerDutyNotificationConfigTest.java │ │ ├── PagerDutyNotificationTest.java │ │ └── client │ │ ├── ClientFactoryTest.java │ │ ├── MessageFactoryTest.java │ │ └── PagerDutyTest.java └── web │ ├── PagerDutyNotificationForm.jsx │ ├── PagerDutyNotificationSummary.jsx │ └── index.jsx └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | *.ipr 4 | *.iws 5 | .classpath 6 | .project 7 | .settings/ 8 | target/ 9 | dependency-reduced-pom.xml 10 | node_modules 11 | node 12 | build 13 | build.config.js.sample 14 | yarn.lock 15 | .travis.yml 16 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Oliver Zeigermann 21 | Oliver Zeigermann 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: java 3 | jdk: 4 | - openjdk8 5 | addons: 6 | apt: 7 | packages: 8 | - rpm 9 | install: 10 | - git clone --branch 3.2 --depth=1 --no-single-branch https://github.com/Graylog2/graylog2-server ../graylog2-server 11 | - (cd ../graylog2-server && mvn -DskipTests=true compile -B -V) 12 | - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -Dskip.web.build=true -B -V 13 | script: 14 | - mvn package -B 15 | before_deploy: 16 | - mvn jdeb:jdeb && export RELEASE_DEB_FILE=$(ls target/*.deb) 17 | - mvn rpm:rpm && export RELEASE_RPM_FILE=$(find target/ -name '*.rpm' | tail -1) 18 | - rm -f target/original-*.jar 19 | - export RELEASE_PKG_FILE=$(ls target/*.jar) 20 | - echo "Deploying release to GitHub releases" 21 | deploy: 22 | provider: releases 23 | api_key: 24 | secure: VPPvEekibGYSb/Jh8C99NSBCZuOMiuKGor5qUBhy2KYIUbteQz8Xuil2t/64YUtzBJfd7kGdNDT3pXP6v8qVts0gIroJzGL1e/rbLPQF8vBRmc5iOWNhb9zrrMIY6puNa6bpht+URxFAUJBKp8UmmOPTyfy2TOkDGSPQntorMZ0= 25 | file: 26 | - "${RELEASE_PKG_FILE}" 27 | - "${RELEASE_DEB_FILE}" 28 | - "${RELEASE_RPM_FILE}" 29 | skip_cleanup: true 30 | on: 31 | tags: true 32 | jdk: openjdk8 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PagerDutyNotificationPlugin Plugin for Graylog 2 | 3 | A Notification plugin to integrate Graylog with PagerDuty as documented 4 | [here](https://developer.pagerduty.com/docs/events-api-v2/trigger-events/). 5 | 6 | **Required Graylog version:** 3.3 and later 7 | 8 | Deprecated 9 | ---------- 10 | **As of Graylog version 4.0.0, PagerDuty notifications are integrated into the core 11 | product. Do not use the graylog-labs plugin on versions 4.x and above as it lacks 12 | support for new notification types.** 13 | 14 | Installation 15 | ------------ 16 | 17 | [Download the plugin](https://github.com/graylog-labs/graylog-plugin-pagerduty/releases) 18 | and place the `.jar` file in your Graylog plugin directory. The plugin directory 19 | is the `plugins/` folder relative from your `graylog-server` directory by default 20 | and can be configured in your `graylog.conf` file. 21 | 22 | Restart `graylog-server` and you are done. 23 | 24 | Usage 25 | ----- 26 | 27 | After deploying the plugin, a new Notification type will be available to select in 28 | the alerts screen. For more information about setting up an alert please 29 | [see](https://docs.graylog.org/en/3.1/pages/streams/alerts.html). 30 | 31 | ![Screenshot: Notification Type](images/pagerduty-notification-1.png) 32 | 33 | The following configuration parameters are required, 34 | 35 | ![Screenshot: Notification Type](images/pagerduty-notification-2.png) 36 | 37 | * _Routing Key_: The PagerDuty Routing Key defined as "[...] the 32 character 38 | Integration Key for an integration on a service or on a global ruleset" 39 | [here](https://developer.pagerduty.com/docs/events-api-v2/trigger-events/). 40 | * _Incident Key Prefix_: The prefix to identify the event in PagerDuty. 41 | * _Client Name_: A String to identify the integration in PagerDuty. 42 | * _Client URL_: This will add a link to the desired destination URL that will be 43 | included in the event. The PagerDuty event will also include a direct link to a 44 | Graylog search query using this URL. 45 | 46 | The following configuration parameters are optional, 47 | * _Use Custom Incident Key_: Enabling it will generate a custom deduplication 48 | key for correlating, the value will follow the format, 49 | 50 | ``` Incident Key Prefix/[Source Streams Separated by Comma]/Event Title ``` 51 | 52 | This is an example of a notification triggered from Graylog. 53 | 54 | ![Screenshot: Notification Type](images/pagerduty-notification-3.png) 55 | 56 | Development 57 | ----------- 58 | 59 | You can improve your development experience for the web interface part of your plugin 60 | dramatically by making use of hot reloading. To do this, do the following: 61 | 62 | * `git clone https://github.com/Graylog2/graylog2-server.git` 63 | * `cd graylog2-server/graylog2-web-interface` 64 | * `ln -s $YOURPLUGIN plugin/` 65 | * `npm install && npm start` 66 | 67 | Getting started 68 | --------------- 69 | 70 | This project is using Maven 3 and requires Java 8 or higher. 71 | 72 | * Clone this repository. 73 | * Run `mvn package` to build a JAR file. 74 | * Optional: Run `mvn jdeb:jdeb` and `mvn rpm:rpm` to create a DEB and RPM package respectively. 75 | * Copy generated JAR file in target directory to your Graylog plugin directory. 76 | * Restart the Graylog. 77 | 78 | Plugin Release 79 | -------------- 80 | 81 | We are using the maven release plugin: 82 | 83 | ``` 84 | $ mvn release:prepare 85 | [...] 86 | $ mvn release:perform 87 | ``` 88 | 89 | This sets the version numbers, creates a tag and pushes to GitHub. Travis CI will build the release artifacts and upload to GitHub automatically. 90 | -------------------------------------------------------------------------------- /build.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | // Make sure that this is the correct path to the web interface part of the Graylog server repository. 5 | web_src_path: path.resolve(__dirname, '../graylog2-server', 'graylog2-web-interface'), 6 | }; 7 | -------------------------------------------------------------------------------- /images/pagerduty-notification-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/graylog-labs/graylog-plugin-pagerduty/db3d6f9ab9a1e02784c6d15cd57e0064f004cdf1/images/pagerduty-notification-1.png -------------------------------------------------------------------------------- /images/pagerduty-notification-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/graylog-labs/graylog-plugin-pagerduty/db3d6f9ab9a1e02784c6d15cd57e0064f004cdf1/images/pagerduty-notification-2.png -------------------------------------------------------------------------------- /images/pagerduty-notification-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/graylog-labs/graylog-plugin-pagerduty/db3d6f9ab9a1e02784c6d15cd57e0064f004cdf1/images/pagerduty-notification-3.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "PagerDutyNotificationPlugin", 3 | "version": "1.0.0-SNAPSHOT", 4 | "description": "", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/graylog-labs/graylog-plugin-pagerduty" 8 | }, 9 | "scripts": { 10 | "build": "webpack", 11 | "lint": "eslint -c .eslintrc src/**/*", 12 | "test": "jest" 13 | }, 14 | "keywords": [ 15 | "graylog" 16 | ], 17 | "author": "Graylog Labs ", 18 | "license": "MIT", 19 | "dependencies": { 20 | }, 21 | "devDependencies": { 22 | "graylog-web-plugin": "file:../graylog2-server/graylog2-web-interface/packages/graylog-web-plugin" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.graylog.plugins 7 | graylog-plugin-web-parent 8 | 3.1.0 9 | ../graylog2-server/graylog-plugin-parent/graylog-plugin-web-parent 10 | 11 | 12 | graylog-plugin-pagerduty 13 | 2.0.1-SNAPSHOT 14 | jar 15 | 16 | ${project.artifactId} 17 | Graylog ${project.artifactId} plugin. 18 | https://www.graylog.org 19 | 20 | 21 | 22 | Graylog Labs 23 | Graylog Labs 24 | 25 | 26 | 27 | 28 | scm:git:git@github.com:graylog-labs/graylog-plugin-pagerduty.git 29 | scm:git:git@github.com:graylog-labs/graylog-plugin-pagerduty.git 30 | https://github.com/graylog-labs/graylog-plugin-pagerduty 31 | HEAD 32 | 33 | 34 | 35 | UTF-8 36 | 1.8 37 | 1.8 38 | 39 | 40 | true 41 | 42 | ${project.parent.version} 43 | /usr/share/graylog-server/plugin 44 | 45 | 46 | 47 | 48 | sonatype-nexus-snapshots 49 | Sonatype Nexus Snapshots 50 | https://oss.sonatype.org/content/repositories/snapshots 51 | 52 | 53 | sonatype-nexus-staging 54 | Nexus Release Repository 55 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 56 | 57 | 58 | 59 | 60 | 61 | 62 | sonatype-nexus-snapshots 63 | Sonatype Nexus Snapshots 64 | https://oss.sonatype.org/content/repositories/snapshots 65 | 66 | false 67 | 68 | 69 | true 70 | 71 | 72 | 73 | sonatype-nexus-releases 74 | Sonatype Nexus Releases 75 | https://oss.sonatype.org/content/repositories/releases 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.graylog2 88 | graylog2-server 89 | provided 90 | 91 | 92 | 93 | org.graylog2 94 | graylog2-server 95 | ${graylog.version} 96 | test-jar 97 | test 98 | 99 | 100 | junit 101 | junit 102 | 4.13 103 | test 104 | 105 | 106 | org.mockito 107 | mockito-core 108 | 3.2.4 109 | test 110 | 111 | 112 | 113 | 114 | 115 | ${web.build-dir} 116 | 117 | src/main/resources 118 | true 119 | 120 | 121 | 122 | 123 | maven-assembly-plugin 124 | 125 | true 126 | 127 | 128 | 129 | 130 | org.apache.maven.plugins 131 | maven-jar-plugin 132 | 133 | 134 | 135 | ${project.groupId}.${project.artifactId} 136 | 137 | 138 | 139 | 140 | 141 | 142 | org.apache.maven.plugins 143 | maven-shade-plugin 144 | 145 | false 146 | 147 | 148 | 149 | package 150 | 151 | shade 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | org.apache.maven.plugins 164 | maven-release-plugin 165 | 166 | true 167 | forked-path 168 | @{project.version} 169 | clean test 170 | package 171 | 172 | 173 | 174 | 175 | jdeb 176 | org.vafer 177 | 178 | ${project.build.directory}/${project.artifactId}-${project.version}.deb 179 | 180 | 181 | ${project.build.directory}/${project.build.finalName}.jar 182 | file 183 | 184 | perm 185 | ${graylog.plugin-dir} 186 | 644 187 | root 188 | root 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | org.codehaus.mojo 197 | rpm-maven-plugin 198 | 199 | Application/Internet 200 | 201 | /usr 202 | 203 | 204 | _unpackaged_files_terminate_build 0 205 | _binaries_in_noarch_packages_terminate_build 0 206 | 207 | 644 208 | 755 209 | root 210 | root 211 | 212 | 213 | ${graylog.plugin-dir} 214 | 215 | 216 | ${project.build.directory}/ 217 | 218 | ${project.build.finalName}.jar 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | web-interface-build 231 | 232 | 233 | !skip.web.build 234 | 235 | 236 | 237 | 238 | 239 | com.github.eirslett 240 | frontend-maven-plugin 241 | 242 | 243 | 244 | install node and yarn 245 | 246 | install-node-and-yarn 247 | 248 | 249 | ${nodejs.version} 250 | ${yarn.version} 251 | 252 | 253 | 254 | 255 | yarn install 256 | 257 | yarn 258 | 259 | 260 | 261 | install 262 | 263 | 264 | 265 | 266 | yarn run build 267 | 268 | yarn 269 | 270 | 271 | run build 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | -------------------------------------------------------------------------------- /src/deb/control/control: -------------------------------------------------------------------------------- 1 | Package: [[name]] 2 | Version: [[version]] 3 | Architecture: all 4 | Maintainer: Graylog Labs 5 | Section: web 6 | Priority: optional 7 | Depends: graylog-server | graylog-radio 8 | Description: [[description]] 9 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/PagerDutyNotification.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import java.io.IOException; 22 | import java.util.List; 23 | import javax.inject.Inject; 24 | import org.graylog.events.notifications.EventNotification; 25 | import org.graylog.events.notifications.EventNotificationContext; 26 | import org.graylog.events.notifications.EventNotificationException; 27 | import org.graylog.plugins.pagerduty.client.ClientFactory; 28 | import org.graylog.plugins.pagerduty.client.PagerDuty; 29 | import org.graylog.plugins.pagerduty.dto.PagerDutyResponse; 30 | import org.graylog2.streams.StreamService; 31 | 32 | /** 33 | * Main class that focuses on event notifications that should be send to PagerDuty. 34 | * 35 | * @author Edgar Molina 36 | * 37 | */ 38 | public class PagerDutyNotification implements EventNotification 39 | { 40 | private final StreamService streamService; 41 | private final ClientFactory clientFactory; 42 | 43 | @Inject 44 | PagerDutyNotification(StreamService streamService) { 45 | this(streamService, new ClientFactory()); 46 | } 47 | 48 | PagerDutyNotification(StreamService streamService, ClientFactory clientFactory) { 49 | this.streamService = streamService; 50 | this.clientFactory = clientFactory; 51 | } 52 | 53 | public interface Factory extends EventNotification.Factory { 54 | @Override 55 | PagerDutyNotification create(); 56 | } 57 | 58 | @Override 59 | public void execute(EventNotificationContext ctx) throws EventNotificationException { 60 | final PagerDutyNotificationConfig config = 61 | (PagerDutyNotificationConfig) ctx.notificationConfig(); 62 | 63 | try (PagerDuty client = clientFactory.create(streamService, config)) { 64 | PagerDutyResponse response = client.trigger(ctx); 65 | List errors = response.getErrors(); 66 | if (errors != null && errors.size() > 0) { 67 | throw new IllegalStateException( 68 | "There was an error triggering the PagerDuty event, details: " + errors); 69 | } 70 | } 71 | catch (IOException e) { 72 | throw new IllegalStateException( 73 | "There was an exception triggering the PagerDuty event.", e); 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/PagerDutyNotificationConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonIgnore; 23 | import com.fasterxml.jackson.annotation.JsonProperty; 24 | import com.fasterxml.jackson.annotation.JsonTypeName; 25 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 26 | import com.google.auto.value.AutoValue; 27 | import java.net.URI; 28 | import java.net.URISyntaxException; 29 | import org.graylog.events.contentpack.entities.EventNotificationConfigEntity; 30 | import org.graylog.events.event.EventDto; 31 | import org.graylog.events.notifications.EventNotificationConfig; 32 | import org.graylog.events.notifications.EventNotificationExecutionJob; 33 | import org.graylog.scheduler.JobTriggerData; 34 | import org.graylog2.contentpacks.EntityDescriptorIds; 35 | import org.graylog2.contentpacks.model.entities.references.ValueReference; 36 | import org.graylog2.plugin.rest.ValidationResult; 37 | 38 | /** 39 | * Configuration class for Pager Duty notifications. 40 | * 41 | * @author Edgar Molina 42 | */ 43 | 44 | @AutoValue 45 | @JsonTypeName(PagerDutyNotificationConfig.TYPE_NAME) 46 | @JsonDeserialize(builder = PagerDutyNotificationConfig.Builder.class) 47 | public abstract class PagerDutyNotificationConfig implements EventNotificationConfig { 48 | public static final String TYPE_NAME = "pagerduty-notification-v1"; 49 | 50 | static final String FIELD_ROUTING_KEY = "routing_key"; 51 | static final String FIELD_CUSTOM_INCIDENT = "custom_incident"; 52 | static final String FIELD_KEY_PREFIX = "key_prefix"; 53 | static final String FIELD_CLIENT_NAME = "client_name"; 54 | static final String FIELD_CLIENT_URL = "client_url"; 55 | 56 | @JsonProperty(FIELD_ROUTING_KEY) 57 | public abstract String routingKey(); 58 | 59 | @JsonProperty(FIELD_CUSTOM_INCIDENT) 60 | public abstract boolean customIncident(); 61 | 62 | @JsonProperty(FIELD_KEY_PREFIX) 63 | public abstract String keyPrefix(); 64 | 65 | @JsonProperty(FIELD_CLIENT_NAME) 66 | public abstract String clientName(); 67 | 68 | @JsonProperty(FIELD_CLIENT_URL) 69 | public abstract String clientUrl(); 70 | 71 | @JsonIgnore 72 | public JobTriggerData toJobTriggerData(EventDto dto) { 73 | return EventNotificationExecutionJob.Data.builder().eventDto(dto).build(); 74 | } 75 | 76 | public static PagerDutyNotificationConfig.Builder builder() { 77 | return PagerDutyNotificationConfig.Builder.create(); 78 | } 79 | 80 | @JsonIgnore 81 | @Override 82 | public ValidationResult validate() { 83 | final ValidationResult validation = new ValidationResult(); 84 | 85 | if (routingKey().isEmpty()) { 86 | validation.addError(FIELD_ROUTING_KEY, "Routing Key cannot be empty."); 87 | } 88 | else if (routingKey().length() != 32) { 89 | validation.addError(FIELD_ROUTING_KEY, "Routing Key must be 32 characters long."); 90 | } 91 | if (keyPrefix().isEmpty()) { 92 | validation.addError(FIELD_KEY_PREFIX, "Incident Key Prefix cannot be empty."); 93 | } 94 | if (clientName().isEmpty()) { 95 | validation.addError(FIELD_CLIENT_NAME, "Client Name cannot be empty."); 96 | } 97 | if (clientUrl().isEmpty()) { 98 | validation.addError(FIELD_CLIENT_URL, "Client URL cannot be empty."); 99 | } 100 | else { 101 | try { 102 | final URI clientUri = new URI(clientUrl()); 103 | if (!"http".equals(clientUri.getScheme()) && !"https".equals(clientUri.getScheme())) { 104 | validation.addError( 105 | FIELD_CLIENT_URL, "Client URL must be a valid HTTP or HTTPS URL."); 106 | } 107 | } 108 | catch (URISyntaxException e) { 109 | validation.addError(FIELD_CLIENT_URL, "Couldn't parse Client URL correctly."); 110 | } 111 | } 112 | 113 | return validation; 114 | } 115 | 116 | @AutoValue.Builder 117 | public static abstract class Builder 118 | implements 119 | EventNotificationConfig.Builder { 120 | @JsonCreator 121 | public static PagerDutyNotificationConfig.Builder create() { 122 | return new AutoValue_PagerDutyNotificationConfig.Builder().type(TYPE_NAME); 123 | } 124 | 125 | @JsonProperty(FIELD_ROUTING_KEY) 126 | public abstract PagerDutyNotificationConfig.Builder routingKey(String routingKey); 127 | 128 | @JsonProperty(FIELD_CUSTOM_INCIDENT) 129 | public abstract PagerDutyNotificationConfig.Builder customIncident(boolean customIncident); 130 | 131 | @JsonProperty(FIELD_KEY_PREFIX) 132 | public abstract PagerDutyNotificationConfig.Builder keyPrefix(String keyPrefix); 133 | 134 | @JsonProperty(FIELD_CLIENT_NAME) 135 | public abstract PagerDutyNotificationConfig.Builder clientName(String clientName); 136 | 137 | @JsonProperty(FIELD_CLIENT_URL) 138 | public abstract PagerDutyNotificationConfig.Builder clientUrl(String clientUrl); 139 | 140 | public abstract PagerDutyNotificationConfig build(); 141 | } 142 | 143 | @Override 144 | public EventNotificationConfigEntity toContentPackEntity( 145 | EntityDescriptorIds entityDescriptorIds) { 146 | return PagerDutyNotificationConfigEntity 147 | .builder() 148 | .routingKey(ValueReference.of(routingKey())) 149 | .customIncident(ValueReference.of(customIncident())) 150 | .keyPrefix(ValueReference.of(keyPrefix())) 151 | .clientName(ValueReference.of(clientName())) 152 | .clientUrl(ValueReference.of(clientUrl())) 153 | .build(); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/PagerDutyNotificationConfigEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.annotation.JsonTypeName; 24 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 25 | import com.google.auto.value.AutoValue; 26 | import org.graylog.events.contentpack.entities.EventNotificationConfigEntity; 27 | import org.graylog.events.notifications.EventNotificationConfig; 28 | import org.graylog.events.notifications.types.HTTPEventNotificationConfig; 29 | import org.graylog2.contentpacks.model.entities.EntityDescriptor; 30 | import org.graylog2.contentpacks.model.entities.references.ValueReference; 31 | 32 | import java.util.Map; 33 | 34 | /** 35 | * Configuration entity for PagerDuty notification events. 36 | * 37 | * @author Edgar Molina 38 | * 39 | */ 40 | @AutoValue 41 | @JsonTypeName(PagerDutyNotificationConfigEntity.TYPE_NAME) 42 | @JsonDeserialize(builder = PagerDutyNotificationConfigEntity.Builder.class) 43 | public abstract class PagerDutyNotificationConfigEntity implements EventNotificationConfigEntity { 44 | public static final String TYPE_NAME = "pagerduty-notification-v1"; 45 | 46 | @JsonProperty(PagerDutyNotificationConfig.FIELD_ROUTING_KEY) 47 | public abstract ValueReference routingKey(); 48 | 49 | @JsonProperty(PagerDutyNotificationConfig.FIELD_CUSTOM_INCIDENT) 50 | public abstract ValueReference customIncident(); 51 | 52 | @JsonProperty(PagerDutyNotificationConfig.FIELD_KEY_PREFIX) 53 | public abstract ValueReference keyPrefix(); 54 | 55 | @JsonProperty(PagerDutyNotificationConfig.FIELD_CLIENT_NAME) 56 | public abstract ValueReference clientName(); 57 | 58 | @JsonProperty(PagerDutyNotificationConfig.FIELD_CLIENT_URL) 59 | public abstract ValueReference clientUrl(); 60 | 61 | public static Builder builder() { 62 | return Builder.create(); 63 | } 64 | 65 | public abstract Builder toBuilder(); 66 | 67 | @AutoValue.Builder 68 | public static abstract class Builder implements EventNotificationConfigEntity.Builder { 69 | 70 | @JsonCreator 71 | public static Builder create() { 72 | return new AutoValue_PagerDutyNotificationConfigEntity.Builder().type(TYPE_NAME); 73 | } 74 | 75 | @JsonProperty(PagerDutyNotificationConfig.FIELD_ROUTING_KEY) 76 | public abstract Builder routingKey(ValueReference routingKey); 77 | 78 | @JsonProperty(PagerDutyNotificationConfig.FIELD_CUSTOM_INCIDENT) 79 | public abstract Builder customIncident(ValueReference customIncident); 80 | 81 | @JsonProperty(PagerDutyNotificationConfig.FIELD_KEY_PREFIX) 82 | public abstract Builder keyPrefix(ValueReference keyPrefix); 83 | 84 | @JsonProperty(PagerDutyNotificationConfig.FIELD_CLIENT_NAME) 85 | public abstract Builder clientName(ValueReference clientName); 86 | 87 | @JsonProperty(PagerDutyNotificationConfig.FIELD_CLIENT_URL) 88 | public abstract Builder clientUrl(ValueReference clientUrl); 89 | 90 | public abstract PagerDutyNotificationConfigEntity build(); 91 | } 92 | 93 | @Override 94 | public EventNotificationConfig toNativeEntity( 95 | Map parameters, 96 | Map nativeEntities) { 97 | return PagerDutyNotificationConfig.builder() 98 | .routingKey(routingKey().asString(parameters)) 99 | .customIncident(customIncident().asBoolean(parameters)) 100 | .keyPrefix(keyPrefix().asString(parameters)) 101 | .clientName(clientName().asString(parameters)) 102 | .clientUrl(clientUrl().asString(parameters)) 103 | .build(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/PagerDutyNotificationPluginMetaData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import org.graylog2.plugin.PluginMetaData; 22 | import org.graylog2.plugin.ServerStatus; 23 | import org.graylog2.plugin.Version; 24 | 25 | import java.net.URI; 26 | import java.util.Collections; 27 | import java.util.Set; 28 | 29 | //Auto-generated by Graylog (graylog-project). 30 | 31 | public class PagerDutyNotificationPluginMetaData implements PluginMetaData { 32 | private static final String PLUGIN_PROPERTIES = 33 | "org.graylog.plugins.graylog-plugin-pagerduty/graylog-plugin.properties"; 34 | 35 | @Override 36 | public String getUniqueId() { 37 | return "org.graylog.plugins.pagerduty.PagerDutyNotificationPluginPlugin"; 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return "PagerDutyNotificationPlugin"; 43 | } 44 | 45 | @Override 46 | public String getAuthor() { 47 | return "Graylog Labs"; 48 | } 49 | 50 | @Override 51 | public URI getURL() { 52 | return URI.create("https://github.com/graylog-labs/graylog-plugin-pagerduty"); 53 | } 54 | 55 | @Override 56 | public Version getVersion() { 57 | return Version.fromPluginProperties( 58 | getClass(), 59 | PLUGIN_PROPERTIES, 60 | "version", 61 | Version.from(1, 0, 0, "unknown")); 62 | } 63 | 64 | @Override 65 | public String getDescription() { 66 | return "Plugin to send notifications to Pager Duty"; 67 | } 68 | 69 | @Override 70 | public Version getRequiredVersion() { 71 | return Version.fromPluginProperties( 72 | getClass(), 73 | PLUGIN_PROPERTIES, 74 | "graylog.version", 75 | Version.from(3, 1, 0, "unknown")); 76 | } 77 | 78 | @Override 79 | public Set getRequiredCapabilities() { 80 | return Collections.emptySet(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/PagerDutyNotificationPluginModule.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import org.graylog2.plugin.PluginModule; 22 | 23 | //Auto-generated by Graylog (graylog-project). 24 | 25 | public class PagerDutyNotificationPluginModule extends PluginModule { 26 | @Override 27 | protected void configure() { 28 | addNotificationType( 29 | PagerDutyNotificationConfig.TYPE_NAME, 30 | PagerDutyNotificationConfig.class, 31 | PagerDutyNotification.class, 32 | PagerDutyNotification.Factory.class); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/PagerDutyNotificationPluginPlugin.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import org.graylog2.plugin.Plugin; 22 | import org.graylog2.plugin.PluginMetaData; 23 | import org.graylog2.plugin.PluginModule; 24 | 25 | import java.util.Collection; 26 | import java.util.Collections; 27 | 28 | // Auto-generated by Graylog (graylog-project). 29 | 30 | public class PagerDutyNotificationPluginPlugin implements Plugin { 31 | @Override 32 | public PluginMetaData metadata() { 33 | return new PagerDutyNotificationPluginMetaData(); 34 | } 35 | 36 | @Override 37 | public Collection modules() { 38 | return Collections.singletonList(new PagerDutyNotificationPluginModule()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/client/ClientFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.client; 20 | 21 | import org.graylog.plugins.pagerduty.PagerDutyNotificationConfig; 22 | import org.graylog2.streams.StreamService; 23 | 24 | /** 25 | * Factory class for the PagerDuty client. 26 | * 27 | * @author Edgar Molina 28 | * 29 | */ 30 | public class ClientFactory { 31 | public PagerDuty create(StreamService streamService, PagerDutyNotificationConfig config) { 32 | return new PagerDuty(streamService, config); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/client/MessageFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.client; 20 | 21 | import java.net.MalformedURLException; 22 | import java.net.URL; 23 | import java.util.Arrays; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.stream.Collectors; 28 | import org.apache.commons.lang3.StringUtils; 29 | import org.graylog.events.event.EventDto; 30 | import org.graylog.events.notifications.EventNotificationContext; 31 | import org.graylog.events.processor.EventDefinitionDto; 32 | import org.graylog.events.processor.aggregation.AggregationEventProcessorConfig; 33 | import org.graylog.plugins.pagerduty.PagerDutyNotificationConfig; 34 | import org.graylog.plugins.pagerduty.dto.Link; 35 | import org.graylog.plugins.pagerduty.dto.PagerDutyMessage; 36 | import org.graylog2.plugin.streams.Stream; 37 | import org.graylog2.streams.StreamService; 38 | 39 | /** 40 | * Factory class for PagerDuty messages, heavily based on the works of the cited authors. 41 | * 42 | * @author Jochen Schalanda 43 | * @author James Carr 44 | * @author Dennis Oelkers 45 | * @author Padma Liyanage 46 | * @author Edgar Molina 47 | */ 48 | class MessageFactory { 49 | private static final List PAGER_DUTY_PRIORITIES = 50 | Arrays.asList("info", "warning", "critical"); 51 | private final StreamService streamService; 52 | private final PagerDutyNotificationConfig config; 53 | 54 | MessageFactory(StreamService streamService, PagerDutyNotificationConfig config) { 55 | this.streamService = streamService; 56 | this.config = config; 57 | } 58 | 59 | PagerDutyMessage createTriggerMessage(EventNotificationContext ctx) { 60 | final EventDto event = ctx.event(); 61 | String eventTitle = "Undefined"; 62 | String eventPriority = PAGER_DUTY_PRIORITIES.get(0); 63 | 64 | if (ctx.eventDefinition().isPresent()) { 65 | eventTitle = ctx.eventDefinition().get().title(); 66 | 67 | int priority = ctx.eventDefinition().get().priority() - 1; 68 | if (priority >= 0 && priority <= 2) { 69 | eventPriority = PAGER_DUTY_PRIORITIES.get(priority); 70 | } 71 | } 72 | 73 | List streamLinks = 74 | streamService 75 | .loadByIds(event.sourceStreams()) 76 | .stream() 77 | .map(stream -> buildStreamWithUrl(stream, ctx)) 78 | .collect(Collectors.toList()); 79 | 80 | String dedupKey = ""; 81 | if (config.customIncident()) { 82 | dedupKey = String.format( 83 | "%s/%s/%s", config.keyPrefix(), event.sourceStreams(), eventTitle); 84 | } 85 | 86 | 87 | Map payload = new HashMap(); 88 | payload.put("summary", event.message()); 89 | payload.put("source", "Graylog:" + event.sourceStreams()); 90 | payload.put("severity", eventPriority); 91 | payload.put("timestamp", event.eventTimestamp().toString()); 92 | payload.put("component", "GraylogAlerts"); 93 | payload.put("group", event.sourceStreams().toString()); 94 | payload.put("class", "alerts"); 95 | 96 | return new PagerDutyMessage( 97 | config.routingKey(), 98 | "trigger", 99 | dedupKey, 100 | config.clientName(), 101 | config.clientUrl(), 102 | streamLinks, 103 | payload); 104 | } 105 | 106 | private Link buildStreamWithUrl(Stream stream, EventNotificationContext ctx) { 107 | final String graylogUrl = config.clientUrl(); 108 | String streamUrl = 109 | StringUtils.appendIfMissing(graylogUrl, "/") + "streams/" + stream.getId() + "/search"; 110 | 111 | if (ctx.eventDefinition().isPresent()) { 112 | EventDefinitionDto eventDefinitionDto = ctx.eventDefinition().get(); 113 | if (eventDefinitionDto.config() instanceof AggregationEventProcessorConfig) { 114 | String query = 115 | ((AggregationEventProcessorConfig) eventDefinitionDto.config()).query(); 116 | streamUrl += "?q=" + query; 117 | } 118 | } 119 | try { 120 | return new Link(new URL(streamUrl), stream.getTitle()); 121 | } 122 | catch (MalformedURLException e) { 123 | throw new IllegalStateException("Error when building the stream link URL.", e); 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/client/PagerDuty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.client; 20 | 21 | import com.fasterxml.jackson.databind.ObjectMapper; 22 | import com.google.common.annotations.VisibleForTesting; 23 | import java.io.IOException; 24 | import org.apache.http.client.methods.CloseableHttpResponse; 25 | import org.apache.http.client.methods.HttpPost; 26 | import org.apache.http.entity.StringEntity; 27 | import org.apache.http.impl.client.CloseableHttpClient; 28 | import org.apache.http.impl.client.HttpClients; 29 | import org.graylog.events.notifications.EventNotificationContext; 30 | import org.graylog.plugins.pagerduty.PagerDutyNotificationConfig; 31 | import org.graylog.plugins.pagerduty.dto.PagerDutyResponse; 32 | import org.graylog2.streams.StreamService; 33 | import org.slf4j.Logger; 34 | import org.slf4j.LoggerFactory; 35 | 36 | /** 37 | * The Pager Duty REST client implementation class compatible with events V2. For more information 38 | * about the event structure please see 39 | * the api. 40 | * 41 | * This class is heavily based on the work commited by Jochen, James and Dennis 42 | * here. 43 | * 44 | * @author Jochen Schalanda 45 | * @author James Carr 46 | * @author Dennis Oelkers 47 | * @author Padma Liyanage 48 | * @author Edgar Molina 49 | */ 50 | public class PagerDuty implements AutoCloseable { 51 | private static final String PAGER_DUTY_NOTIFICATION_PLUGIN = "PagerDutyNotificationPlugin"; 52 | private static final String API_URL = "https://events.pagerduty.com/v2/enqueue"; 53 | private final Logger logger; 54 | private final ObjectMapper objectMapper; 55 | private final CloseableHttpClient httpClient; 56 | private final MessageFactory messageFactory; 57 | 58 | public PagerDuty(final StreamService streamService, final PagerDutyNotificationConfig config) { 59 | this( 60 | streamService, 61 | config, 62 | HttpClients.createDefault(), 63 | new ObjectMapper(), 64 | new MessageFactory(streamService, config), 65 | LoggerFactory.getLogger(PAGER_DUTY_NOTIFICATION_PLUGIN)); 66 | } 67 | 68 | @VisibleForTesting 69 | PagerDuty( 70 | final StreamService streamService, 71 | final PagerDutyNotificationConfig config, 72 | final CloseableHttpClient httpClient, 73 | final ObjectMapper objectMapper, 74 | final MessageFactory messageFactory, 75 | final Logger logger) { 76 | this.httpClient = httpClient; 77 | this.objectMapper = objectMapper; 78 | this.messageFactory = messageFactory; 79 | this.logger = logger; 80 | } 81 | 82 | public PagerDutyResponse trigger(EventNotificationContext ctx) { 83 | try { 84 | final String payloadString = objectMapper.writeValueAsString( 85 | messageFactory.createTriggerMessage(ctx)); 86 | final StringEntity payloadEntity = new StringEntity(payloadString); 87 | final HttpPost httpPost = new HttpPost(API_URL); 88 | 89 | logger.debug("Triggering event in PagerDuty with context: {}", ctx); 90 | logger.debug("Request Payload: {}", payloadString); 91 | httpPost.setEntity(payloadEntity); 92 | try (CloseableHttpResponse response = httpClient.execute(httpPost)) 93 | { 94 | return objectMapper.readValue( 95 | response.getEntity().getContent(), PagerDutyResponse.class); 96 | } 97 | } 98 | catch (IOException e) { 99 | throw new IllegalStateException( 100 | "There was an error sending the notification event.", e); 101 | } 102 | } 103 | 104 | @Override 105 | public void close() throws IOException { 106 | httpClient.close(); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/dto/Link.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.dto; 20 | 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import java.net.URL; 23 | 24 | /** 25 | * @author Edgar Molina 26 | * 27 | */ 28 | public class Link { 29 | @JsonProperty("href") 30 | private final URL href; 31 | @JsonProperty("text") 32 | private final String text; 33 | 34 | public Link(URL href, String text) { 35 | this.href = href; 36 | this.text = text; 37 | } 38 | 39 | public URL getHref() { 40 | return href; 41 | } 42 | 43 | public String getText() { 44 | return text; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/dto/PagerDutyMessage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.dto; 20 | 21 | import com.fasterxml.jackson.annotation.JsonInclude; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * @author Edgar Molina 28 | * 29 | */ 30 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 31 | public class PagerDutyMessage { 32 | @JsonProperty("routing_key") 33 | private final String routingKey; 34 | @JsonProperty("event_action") 35 | private final String eventAction; 36 | @JsonProperty("dedup_key") 37 | private final String dedupKey; 38 | @JsonProperty("client") 39 | private final String client; 40 | @JsonProperty("client_url") 41 | private final String clientUrl; 42 | @JsonProperty("links") 43 | private final List links; 44 | @JsonProperty("payload") 45 | private final Map payload; 46 | 47 | public PagerDutyMessage( 48 | String routingKey, 49 | String eventAction, 50 | String dedupKey, 51 | String client, 52 | String clientUrl, 53 | List links, 54 | Map payload) { 55 | this.routingKey = routingKey; 56 | this.eventAction = eventAction; 57 | this.dedupKey = dedupKey; 58 | this.client = client; 59 | this.clientUrl = clientUrl; 60 | this.links = links; 61 | this.payload = payload; 62 | } 63 | 64 | public String getRoutingKey() { 65 | return routingKey; 66 | } 67 | 68 | public String getEventAction() { 69 | return eventAction; 70 | } 71 | 72 | public String getDedupKey() { 73 | return dedupKey; 74 | } 75 | 76 | public String getClient() { 77 | return client; 78 | } 79 | 80 | public String getClientUrl() { 81 | return clientUrl; 82 | } 83 | 84 | public List getLinks() { 85 | return links; 86 | } 87 | 88 | public Map getPayload() { 89 | return payload; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/org/graylog/plugins/pagerduty/dto/PagerDutyResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.dto; 20 | 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import java.util.List; 23 | 24 | /** 25 | * @author Edgar Molina 26 | * 27 | */ 28 | public class PagerDutyResponse { 29 | @JsonProperty("status") 30 | private String status; 31 | @JsonProperty("message") 32 | private String message; 33 | @JsonProperty("dedup_key") 34 | private String dedupKey; 35 | @JsonProperty("errors") 36 | private List errors; 37 | 38 | public String getStatus() { 39 | return status; 40 | } 41 | 42 | public String getMessage() { 43 | return message; 44 | } 45 | 46 | public String getDedupKey() { 47 | return dedupKey; 48 | } 49 | 50 | public List getErrors() { 51 | return errors; 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/org.graylog2.plugin.Plugin: -------------------------------------------------------------------------------- 1 | org.graylog.plugins.pagerduty.PagerDutyNotificationPluginPlugin -------------------------------------------------------------------------------- /src/main/resources/org.graylog.plugins.graylog-plugin-pagerduty/graylog-plugin.properties: -------------------------------------------------------------------------------- 1 | # The plugin version 2 | version=${project.version} 3 | 4 | # The required Graylog server version 5 | graylog.version=${graylog.version} 6 | 7 | # When set to true (the default) the plugin gets a separate class loader 8 | # when loading the plugin. When set to false, the plugin shares a class loader 9 | # with other plugins that have isolated=false. 10 | # 11 | # Do not disable this unless this plugin depends on another plugin! 12 | isolated=true 13 | -------------------------------------------------------------------------------- /src/test/java/org/graylog/plugins/pagerduty/PagerDutyNotificationConfigTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import org.graylog2.plugin.rest.ValidationResult; 23 | import org.junit.Test; 24 | 25 | /** 26 | * @author Edgar Molina 27 | * 28 | */ 29 | public class PagerDutyNotificationConfigTest { 30 | PagerDutyNotificationConfig.Builder sutBuilder = PagerDutyNotificationConfig.Builder.create(); 31 | 32 | @Test 33 | public void testValidConfigurationWithHttp() { 34 | ValidationResult result = 35 | sutBuilder 36 | .routingKey("01234567890123456789012345678901") 37 | .customIncident(false) 38 | .keyPrefix("TestPrefix") 39 | .clientName("TestName") 40 | .clientUrl("http://test/") 41 | .build() 42 | .validate(); 43 | assertEquals("Error count", 0, result.getErrors().size()); 44 | } 45 | 46 | @Test 47 | public void testValidConfigurationWithHttps() { 48 | ValidationResult result = 49 | sutBuilder 50 | .routingKey("01234567890123456789012345678901") 51 | .customIncident(false) 52 | .keyPrefix("TestPrefix") 53 | .clientName("TestName") 54 | .clientUrl("https://test/") 55 | .build() 56 | .validate(); 57 | assertEquals("Error count", 0, result.getErrors().size()); 58 | } 59 | 60 | @Test 61 | public void testEmptyRoutingKeyValidation() { 62 | ValidationResult result = 63 | sutBuilder 64 | .routingKey("") 65 | .customIncident(false) 66 | .keyPrefix("TestPrefix") 67 | .clientName("TestClient") 68 | .clientUrl("http://test/") 69 | .build() 70 | .validate(); 71 | assertEquals("Error count", 1, result.getErrors().size()); 72 | assertEquals( 73 | "Error message", 74 | "{routing_key=[Routing Key cannot be empty.]}", 75 | result.getErrors().toString()); 76 | } 77 | 78 | @Test 79 | public void testTooShortRoutingKey() { 80 | ValidationResult result = 81 | sutBuilder 82 | .routingKey("TestRouting") 83 | .customIncident(false) 84 | .keyPrefix("TestPrefix") 85 | .clientName("TestClient") 86 | .clientUrl("http://test/") 87 | .build() 88 | .validate(); 89 | assertEquals("Error count", 1, result.getErrors().size()); 90 | assertEquals( 91 | "Error message", 92 | "{routing_key=[Routing Key must be 32 characters long.]}", 93 | result.getErrors().toString()); 94 | } 95 | 96 | @Test 97 | public void testTooLongRoutingKey() { 98 | ValidationResult result = 99 | sutBuilder 100 | .routingKey("0123456789012345678901234567890123456789") 101 | .customIncident(false) 102 | .keyPrefix("TestPrefix") 103 | .clientName("TestClient") 104 | .clientUrl("http://test/") 105 | .build() 106 | .validate(); 107 | assertEquals("Error count", 1, result.getErrors().size()); 108 | assertEquals( 109 | "Error message", 110 | "{routing_key=[Routing Key must be 32 characters long.]}", 111 | result.getErrors().toString()); 112 | } 113 | 114 | @Test 115 | public void testEmptyKeyPrefix() { 116 | ValidationResult result = 117 | sutBuilder 118 | .routingKey("01234567890123456789012345678901") 119 | .customIncident(false) 120 | .keyPrefix("") 121 | .clientName("TestClient") 122 | .clientUrl("http://test/") 123 | .build() 124 | .validate(); 125 | assertEquals("Error count", 1, result.getErrors().size()); 126 | assertEquals( 127 | "Error message", 128 | "{key_prefix=[Incident Key Prefix cannot be empty.]}", 129 | result.getErrors().toString()); 130 | } 131 | 132 | @Test 133 | public void testEmptyClientName() { 134 | ValidationResult result = 135 | sutBuilder 136 | .routingKey("01234567890123456789012345678901") 137 | .customIncident(false) 138 | .keyPrefix("TestPrefix") 139 | .clientName("") 140 | .clientUrl("http://test/") 141 | .build() 142 | .validate(); 143 | assertEquals("Error count", 1, result.getErrors().size()); 144 | assertEquals( 145 | "Error message", 146 | "{client_name=[Client Name cannot be empty.]}", 147 | result.getErrors().toString()); 148 | } 149 | 150 | @Test 151 | public void testEmptyClientURL() { 152 | ValidationResult result = 153 | sutBuilder 154 | .routingKey("01234567890123456789012345678901") 155 | .customIncident(false) 156 | .keyPrefix("TestPrefix") 157 | .clientName("TestName") 158 | .clientUrl("") 159 | .build() 160 | .validate(); 161 | assertEquals("Error count", 1, result.getErrors().size()); 162 | assertEquals( 163 | "Error message", 164 | "{client_url=[Client URL cannot be empty.]}", 165 | result.getErrors().toString()); 166 | } 167 | 168 | @Test 169 | public void testWrongClientURLFormat() { 170 | ValidationResult result = 171 | sutBuilder 172 | .routingKey("01234567890123456789012345678901") 173 | .customIncident(false) 174 | .keyPrefix("TestPrefix") 175 | .clientName("TestName") 176 | .clientUrl("te\\st") 177 | .build() 178 | .validate(); 179 | assertEquals("Error count", 1, result.getErrors().size()); 180 | assertEquals( 181 | "Error message", 182 | "{client_url=[Couldn't parse Client URL correctly.]}", 183 | result.getErrors().toString()); 184 | } 185 | 186 | @Test 187 | public void testWrongClientURLProtocol() { 188 | ValidationResult result = 189 | sutBuilder 190 | .routingKey("01234567890123456789012345678901") 191 | .customIncident(false) 192 | .keyPrefix("TestPrefix") 193 | .clientName("TestName") 194 | .clientUrl("git://test/") 195 | .build() 196 | .validate(); 197 | assertEquals("Error count", 1, result.getErrors().size()); 198 | assertEquals( 199 | "Error message", 200 | "{client_url=[Client URL must be a valid HTTP or HTTPS URL.]}", 201 | result.getErrors().toString()); 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/test/java/org/graylog/plugins/pagerduty/PagerDutyNotificationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.mockito.Mockito.verify; 23 | import static org.mockito.Mockito.when; 24 | import static org.mockito.Mockito.doThrow; 25 | 26 | import java.util.Arrays; 27 | import java.io.IOException; 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | import org.graylog.events.notifications.EventNotificationContext; 31 | import org.graylog.events.notifications.EventNotificationException; 32 | import org.graylog.plugins.pagerduty.client.ClientFactory; 33 | import org.graylog.plugins.pagerduty.client.PagerDuty; 34 | import org.graylog.plugins.pagerduty.dto.PagerDutyResponse; 35 | import org.graylog2.streams.StreamService; 36 | import org.junit.Before; 37 | import org.junit.Test; 38 | import org.mockito.Mock; 39 | import org.mockito.MockitoAnnotations; 40 | 41 | /** 42 | * @author Edgar Molina 43 | * 44 | */ 45 | public class PagerDutyNotificationTest { 46 | @Mock 47 | private StreamService streamServiceMock; 48 | @Mock 49 | private ClientFactory clientFactoryMock; 50 | @Mock 51 | private EventNotificationContext contextMock; 52 | @Mock 53 | private PagerDutyNotificationConfig configMock; 54 | @Mock 55 | private PagerDuty clientMock; 56 | @Mock 57 | private PagerDutyResponse responseMock; 58 | 59 | private PagerDutyNotification sut; 60 | 61 | @Before 62 | public void setUp() { 63 | MockitoAnnotations.initMocks(this); 64 | when(contextMock.notificationConfig()).thenReturn(configMock); 65 | when(clientFactoryMock.create(streamServiceMock, configMock)).thenReturn(clientMock); 66 | sut = new PagerDutyNotification(streamServiceMock, clientFactoryMock); 67 | } 68 | 69 | @Test 70 | public void testSuccessfullNotificationTrigger() throws EventNotificationException { 71 | // Setup 72 | when(clientMock.trigger(contextMock)).thenReturn(responseMock); 73 | when(responseMock.getErrors()).thenReturn(null); 74 | 75 | // Execute 76 | sut.execute(contextMock); 77 | 78 | // Assert 79 | verify(clientMock).trigger(contextMock); 80 | verify(responseMock).getErrors(); 81 | } 82 | 83 | @Test 84 | public void testSuccessfulNotificationTriggerWithoutErrors() throws EventNotificationException { 85 | // Setup 86 | when(clientMock.trigger(contextMock)).thenReturn(responseMock); 87 | when(responseMock.getErrors()).thenReturn(new ArrayList<>()); 88 | 89 | // Execute 90 | sut.execute(contextMock); 91 | 92 | // Assert 93 | verify(clientMock).trigger(contextMock); 94 | verify(responseMock).getErrors(); 95 | } 96 | 97 | @Test (expected = IllegalStateException.class) 98 | public void testFailedNotificationTriggerWithErrors() throws EventNotificationException { 99 | // Setup 100 | final List errorsReported = Arrays.asList("first error", "second error"); 101 | when(clientMock.trigger(contextMock)).thenReturn(responseMock); 102 | when(responseMock.getErrors()).thenReturn(errorsReported); 103 | 104 | try { 105 | // Execute 106 | sut.execute(contextMock); 107 | } 108 | catch (IllegalStateException e) { 109 | // Assert 110 | assertEquals( 111 | "Wrong Exception Message", 112 | "There was an error triggering the PagerDuty event, details: " 113 | + "[first error, second error]", 114 | e.getMessage()); 115 | throw e; 116 | } 117 | } 118 | 119 | @Test (expected = IllegalStateException.class) 120 | public void testFailedIOExceptionCreatingTheClient() 121 | throws EventNotificationException, IOException { 122 | // Setup 123 | when(clientMock.trigger(contextMock)).thenReturn(responseMock); 124 | when(responseMock.getErrors()).thenReturn(null); 125 | doThrow(IOException.class).when(clientMock).close(); 126 | 127 | try { 128 | // Execute 129 | sut.execute(contextMock); 130 | } 131 | catch (IllegalStateException e) { 132 | // Assert 133 | assertEquals( 134 | "Wrong Exception Message", 135 | "There was an exception triggering the PagerDuty event.", 136 | e.getMessage()); 137 | throw e; 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/test/java/org/graylog/plugins/pagerduty/client/ClientFactoryTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.client; 20 | 21 | import static org.junit.Assert.assertTrue; 22 | 23 | import org.graylog.plugins.pagerduty.PagerDutyNotificationConfig; 24 | import org.graylog2.streams.StreamService; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.mockito.Mock; 28 | import org.mockito.MockitoAnnotations; 29 | 30 | /** 31 | * @author Edgar Molina 32 | * 33 | */ 34 | public class ClientFactoryTest { 35 | @Mock 36 | private StreamService streamServiceMock; 37 | @Mock 38 | private PagerDutyNotificationConfig configMock; 39 | 40 | private ClientFactory sut; 41 | 42 | @Before 43 | public void setUp() { 44 | MockitoAnnotations.initMocks(this); 45 | sut = new ClientFactory(); 46 | } 47 | 48 | @Test 49 | public void testCreate() { 50 | // Execute 51 | PagerDuty result = sut.create(streamServiceMock, configMock); 52 | 53 | // Assert 54 | assertTrue("Wrong type", result instanceof PagerDuty); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/graylog/plugins/pagerduty/client/MessageFactoryTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.client; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.mockito.Mockito.when; 23 | 24 | import java.util.HashSet; 25 | import java.util.Optional; 26 | import java.util.Set; 27 | import org.graylog.events.event.EventDto; 28 | import org.graylog.events.notifications.EventNotificationContext; 29 | import org.graylog.events.processor.EventDefinitionDto; 30 | import org.graylog.events.processor.aggregation.AggregationEventProcessorConfig; 31 | import org.graylog.plugins.pagerduty.PagerDutyNotificationConfig; 32 | import org.graylog.plugins.pagerduty.dto.Link; 33 | import org.graylog.plugins.pagerduty.dto.PagerDutyMessage; 34 | import org.graylog2.plugin.streams.Stream; 35 | import org.graylog2.streams.StreamService; 36 | import org.joda.time.DateTime; 37 | import org.junit.Before; 38 | import org.junit.Test; 39 | import org.mockito.Mock; 40 | import org.mockito.MockitoAnnotations; 41 | 42 | /** 43 | * @author Edgar Molina 44 | * 45 | */ 46 | public class MessageFactoryTest { 47 | private static final String TEST_EVENT_TITLE = "Test title"; 48 | private static final String CLIENT_NAME = "ClientName"; 49 | private static final String KEY_PREFIX = "KeyPrefix"; 50 | private static final String ROUTING_KEY = "RoutingKey"; 51 | private static final String TEST_STREAM_TITLE = "Test Stream Title"; 52 | private static final String CLIENT_URL = "https://test"; 53 | private static final String STREAM_ID = "0001"; 54 | private static final String TEST_TIMESTAMP = new DateTime(1).toString(); 55 | 56 | @Mock 57 | private StreamService streamServiceMock; 58 | @Mock 59 | private PagerDutyNotificationConfig configMock; 60 | @Mock 61 | private EventDto eventMock; 62 | @Mock 63 | private EventNotificationContext ctxMock; 64 | @Mock 65 | private EventDefinitionDto eventDefinitionMock; 66 | @Mock 67 | private Stream streamMock; 68 | @Mock 69 | private AggregationEventProcessorConfig eventDefinitionConfigMock; 70 | private final Set sourceStreams = new HashSet<>(); 71 | private final Set streams = new HashSet<>(); 72 | private Optional eventDefinition; 73 | 74 | private MessageFactory sut; 75 | 76 | @Before 77 | public void setUp() { 78 | MockitoAnnotations.initMocks(this); 79 | 80 | eventDefinition = Optional.of(eventDefinitionMock); 81 | when(configMock.customIncident()).thenReturn(true); 82 | when(configMock.keyPrefix()).thenReturn(KEY_PREFIX); 83 | when(configMock.routingKey()).thenReturn(ROUTING_KEY); 84 | when(configMock.clientName()).thenReturn(CLIENT_NAME); 85 | when(configMock.clientUrl()).thenReturn(CLIENT_URL); 86 | when(streamMock.getId()).thenReturn(STREAM_ID); 87 | when(streamMock.getTitle()).thenReturn(TEST_STREAM_TITLE); 88 | when(eventMock.sourceStreams()).thenReturn(sourceStreams); 89 | when(eventMock.message()).thenReturn("Test Event Message"); 90 | when(eventMock.eventTimestamp()).thenReturn(new DateTime(1)); 91 | when(streamServiceMock.loadByIds(sourceStreams)).thenReturn(streams); 92 | when(ctxMock.event()).thenReturn(eventMock); 93 | when(eventDefinitionConfigMock.query()).thenReturn("Test=Query"); 94 | when(eventDefinitionMock.title()).thenReturn(TEST_EVENT_TITLE); 95 | when(eventDefinitionMock.priority()).thenReturn(3); 96 | when(eventDefinitionMock.config()).thenReturn(eventDefinitionConfigMock); 97 | when(ctxMock.eventDefinition()).thenReturn(eventDefinition); 98 | 99 | sourceStreams.add(STREAM_ID); 100 | streams.add(streamMock); 101 | 102 | sut = new MessageFactory(streamServiceMock, configMock); 103 | } 104 | 105 | @Test 106 | public void testCriticalMessageWithAllSettingSet() { 107 | // Set up 108 | when(eventDefinitionMock.priority()).thenReturn(3); 109 | 110 | // Execute 111 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 112 | 113 | // Assert 114 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 115 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 116 | assertEquals( 117 | "Wrong DedupKey", 118 | KEY_PREFIX + "/[" + STREAM_ID + "]/" + TEST_EVENT_TITLE, 119 | result.getDedupKey()); 120 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 121 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 122 | assertEquals("Wrong Stream Links Count", 1, result.getLinks().size()); 123 | Link streamLink = result.getLinks().get(0); 124 | assertEquals( 125 | "Wrong Link Href", 126 | "https://test/streams/0001/search?q=Test=Query", 127 | streamLink.getHref().toString()); 128 | assertEquals("Wrong Link Text", TEST_STREAM_TITLE, streamLink.getText()); 129 | assertEquals( 130 | "Wrong Payload", 131 | "{summary=Test Event Message, " 132 | + "severity=critical, " 133 | + "component=GraylogAlerts, source=Graylog:[0001], " 134 | + "class=alerts, " 135 | + "timestamp=" + TEST_TIMESTAMP + ", " 136 | + "group=[0001]}", 137 | result.getPayload().toString()); 138 | } 139 | 140 | @Test 141 | public void testWarningMessageWithAllSettingSet() { 142 | // Set up 143 | when(eventDefinitionMock.priority()).thenReturn(2); 144 | 145 | // Execute 146 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 147 | 148 | // Assert 149 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 150 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 151 | assertEquals( 152 | "Wrong DedupKey", 153 | KEY_PREFIX + "/[" + STREAM_ID + "]/" + TEST_EVENT_TITLE, 154 | result.getDedupKey()); 155 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 156 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 157 | assertEquals("Wrong Stream Links Count", 1, result.getLinks().size()); 158 | Link streamLink = result.getLinks().get(0); 159 | assertEquals( 160 | "Wrong Link Href", 161 | "https://test/streams/0001/search?q=Test=Query", 162 | streamLink.getHref().toString()); 163 | assertEquals("Wrong Link Text", TEST_STREAM_TITLE, streamLink.getText()); 164 | assertEquals( 165 | "Wrong Payload", 166 | "{summary=Test Event Message, " 167 | + "severity=warning, " 168 | + "component=GraylogAlerts, source=Graylog:[0001], " 169 | + "class=alerts, " 170 | + "timestamp=" + TEST_TIMESTAMP + ", " 171 | + "group=[0001]}", 172 | result.getPayload().toString()); 173 | } 174 | 175 | @Test 176 | public void testInfoMessageWithAllSettingSet() { 177 | // Set up 178 | when(eventDefinitionMock.priority()).thenReturn(1); 179 | 180 | // Execute 181 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 182 | 183 | // Assert 184 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 185 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 186 | assertEquals( 187 | "Wrong DedupKey", 188 | KEY_PREFIX + "/[" + STREAM_ID + "]/" + TEST_EVENT_TITLE, 189 | result.getDedupKey()); 190 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 191 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 192 | assertEquals("Wrong Stream Links Count", 1, result.getLinks().size()); 193 | Link streamLink = result.getLinks().get(0); 194 | assertEquals( 195 | "Wrong Link Href", 196 | "https://test/streams/0001/search?q=Test=Query", 197 | streamLink.getHref().toString()); 198 | assertEquals("Wrong Link Text", TEST_STREAM_TITLE, streamLink.getText()); 199 | assertEquals( 200 | "Wrong Payload", 201 | "{summary=Test Event Message, " 202 | + "severity=info, " 203 | + "component=GraylogAlerts, source=Graylog:[0001], " 204 | + "class=alerts, " 205 | + "timestamp=" + TEST_TIMESTAMP + ", " 206 | + "group=[0001]}", 207 | result.getPayload().toString()); 208 | } 209 | 210 | @Test 211 | public void testNegativeSeverityMessage() { 212 | // Set up 213 | when(eventDefinitionMock.priority()).thenReturn(-1); 214 | 215 | // Execute 216 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 217 | 218 | // Assert 219 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 220 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 221 | assertEquals( 222 | "Wrong DedupKey", 223 | KEY_PREFIX + "/[" + STREAM_ID + "]/" + TEST_EVENT_TITLE, 224 | result.getDedupKey()); 225 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 226 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 227 | assertEquals("Wrong Stream Links Count", 1, result.getLinks().size()); 228 | Link streamLink = result.getLinks().get(0); 229 | assertEquals( 230 | "Wrong Link Href", 231 | "https://test/streams/0001/search?q=Test=Query", 232 | streamLink.getHref().toString()); 233 | assertEquals("Wrong Link Text", TEST_STREAM_TITLE, streamLink.getText()); 234 | assertEquals( 235 | "Wrong Payload", 236 | "{summary=Test Event Message, " 237 | + "severity=info, " 238 | + "component=GraylogAlerts, source=Graylog:[0001], " 239 | + "class=alerts, " 240 | + "timestamp=" + TEST_TIMESTAMP + ", " 241 | + "group=[0001]}", 242 | result.getPayload().toString()); 243 | } 244 | 245 | @Test 246 | public void testOutOfRangeSeverityMessage() { 247 | // Set up 248 | when(eventDefinitionMock.priority()).thenReturn(-1); 249 | 250 | // Execute 251 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 252 | 253 | // Assert 254 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 255 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 256 | assertEquals( 257 | "Wrong DedupKey", 258 | KEY_PREFIX + "/[" + STREAM_ID + "]/" + TEST_EVENT_TITLE, 259 | result.getDedupKey()); 260 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 261 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 262 | assertEquals("Wrong Stream Links Count", 1, result.getLinks().size()); 263 | Link streamLink = result.getLinks().get(0); 264 | assertEquals( 265 | "Wrong Link Href", 266 | "https://test/streams/0001/search?q=Test=Query", 267 | streamLink.getHref().toString()); 268 | assertEquals("Wrong Link Text", TEST_STREAM_TITLE, streamLink.getText()); 269 | assertEquals( 270 | "Wrong Payload", 271 | "{summary=Test Event Message, " 272 | + "severity=info, " 273 | + "component=GraylogAlerts, source=Graylog:[0001], " 274 | + "class=alerts, " 275 | + "timestamp=" + TEST_TIMESTAMP + ", " 276 | + "group=[0001]}", 277 | result.getPayload().toString()); 278 | } 279 | 280 | @Test 281 | public void testNoCustomIncident() { 282 | // Set up 283 | when(configMock.customIncident()).thenReturn(false); 284 | 285 | // Execute 286 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 287 | 288 | // Assert 289 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 290 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 291 | assertEquals("Wrong DedupKey", "", result.getDedupKey()); 292 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 293 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 294 | assertEquals("Wrong Stream Links Count", 1, result.getLinks().size()); 295 | Link streamLink = result.getLinks().get(0); 296 | assertEquals( 297 | "Wrong Link Href", 298 | "https://test/streams/0001/search?q=Test=Query", 299 | streamLink.getHref().toString()); 300 | assertEquals("Wrong Link Text", TEST_STREAM_TITLE, streamLink.getText()); 301 | assertEquals( 302 | "Wrong Payload", 303 | "{summary=Test Event Message, " 304 | + "severity=critical, " 305 | + "component=GraylogAlerts, source=Graylog:[0001], " 306 | + "class=alerts, " 307 | + "timestamp=" + TEST_TIMESTAMP + ", " 308 | + "group=[0001]}", 309 | result.getPayload().toString()); 310 | } 311 | 312 | @Test 313 | public void testNoSourceStreams() { 314 | // Set up 315 | sourceStreams.clear(); 316 | streams.clear(); 317 | 318 | // Execute 319 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 320 | 321 | // Assert 322 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 323 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 324 | assertEquals( 325 | "Wrong DedupKey", 326 | KEY_PREFIX + "/[]/" + TEST_EVENT_TITLE, 327 | result.getDedupKey()); 328 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 329 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 330 | assertEquals("Wrong Stream Links Count", 0, result.getLinks().size()); 331 | assertEquals( 332 | "Wrong Payload", 333 | "{summary=Test Event Message, " 334 | + "severity=critical, " 335 | + "component=GraylogAlerts, source=Graylog:[], " 336 | + "class=alerts, " 337 | + "timestamp=" + TEST_TIMESTAMP + ", " 338 | + "group=[]}", 339 | result.getPayload().toString()); 340 | } 341 | 342 | @Test 343 | public void testNoEventDefinition() { 344 | // Set up 345 | eventDefinition = Optional.empty(); 346 | when(ctxMock.eventDefinition()).thenReturn(eventDefinition); 347 | 348 | // Execute 349 | PagerDutyMessage result = sut.createTriggerMessage(ctxMock); 350 | 351 | // Assert 352 | assertEquals("Wrong RoutingKey", ROUTING_KEY, result.getRoutingKey()); 353 | assertEquals("Wrong Event Action", "trigger", result.getEventAction()); 354 | assertEquals( 355 | "Wrong DedupKey", 356 | KEY_PREFIX + "/[" + STREAM_ID + "]/Undefined", 357 | result.getDedupKey()); 358 | assertEquals("Wrong ClientName", CLIENT_NAME, result.getClient()); 359 | assertEquals("Wrong ClientUrl", CLIENT_URL, result.getClientUrl()); 360 | assertEquals("Wrong Stream Links Count", 1, result.getLinks().size()); 361 | Link streamLink = result.getLinks().get(0); 362 | assertEquals( 363 | "Wrong Link Href", 364 | "https://test/streams/0001/search", 365 | streamLink.getHref().toString()); 366 | assertEquals("Wrong Link Text", TEST_STREAM_TITLE, streamLink.getText()); 367 | assertEquals( 368 | "Wrong Payload", 369 | "{summary=Test Event Message, " 370 | + "severity=info, " 371 | + "component=GraylogAlerts, source=Graylog:[0001], " 372 | + "class=alerts, " 373 | + "timestamp=" + TEST_TIMESTAMP + ", " 374 | + "group=[0001]}", 375 | result.getPayload().toString()); 376 | } 377 | 378 | @Test(expected = IllegalStateException.class) 379 | public void testMalformedClientUrl() { 380 | // Set up 381 | when(configMock.clientUrl()).thenReturn("Test\\Wrong\\URL"); 382 | 383 | // Execute 384 | sut.createTriggerMessage(ctxMock); 385 | } 386 | } 387 | -------------------------------------------------------------------------------- /src/test/java/org/graylog/plugins/pagerduty/client/PagerDutyTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of Graylog PagerDuty plugin. 3 | * 4 | * Graylog PagerDuty Plugin is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * Graylog PagerDuty Plugin is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with Graylog PagerDuty Plugin. If not, see . 16 | * 17 | */ 18 | 19 | package org.graylog.plugins.pagerduty.client; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | import static org.mockito.ArgumentMatchers.any; 23 | import static org.mockito.Mockito.atMostOnce; 24 | import static org.mockito.Mockito.doThrow; 25 | import static org.mockito.Mockito.verify; 26 | import static org.mockito.Mockito.when; 27 | 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | import java.nio.charset.StandardCharsets; 31 | 32 | import org.apache.commons.io.IOUtils; 33 | import org.apache.http.HttpEntity; 34 | import org.apache.http.client.ClientProtocolException; 35 | import org.apache.http.client.methods.CloseableHttpResponse; 36 | import org.apache.http.client.methods.HttpPost; 37 | import org.apache.http.impl.client.CloseableHttpClient; 38 | import org.graylog.events.notifications.EventNotificationContext; 39 | import org.graylog.plugins.pagerduty.PagerDutyNotificationConfig; 40 | import org.graylog.plugins.pagerduty.dto.PagerDutyMessage; 41 | import org.graylog.plugins.pagerduty.dto.PagerDutyResponse; 42 | import org.graylog2.streams.StreamService; 43 | import org.junit.Before; 44 | import org.junit.Test; 45 | import org.mockito.ArgumentCaptor; 46 | import org.mockito.Mock; 47 | import org.mockito.MockitoAnnotations; 48 | import org.slf4j.Logger; 49 | 50 | import com.fasterxml.jackson.databind.ObjectMapper; 51 | 52 | /** 53 | * @author Edgar Molina 54 | * 55 | */ 56 | public class PagerDutyTest 57 | { 58 | @Mock 59 | private StreamService streamServiceMock; 60 | @Mock 61 | private PagerDutyNotificationConfig configMock; 62 | @Mock 63 | private CloseableHttpClient httpClientMock; 64 | @Mock 65 | private ObjectMapper objectMapperMock; 66 | @Mock 67 | private MessageFactory messageFactoryMock; 68 | @Mock 69 | private Logger loggerMock; 70 | @Mock 71 | private PagerDutyMessage messageMock; 72 | @Mock 73 | private EventNotificationContext contextMock; 74 | @Mock 75 | private CloseableHttpResponse httpResponseMock; 76 | @Mock 77 | private HttpEntity entityMock; 78 | @Mock 79 | private InputStream contentMock; 80 | @Mock 81 | private PagerDutyResponse pagerDutyResponseMock; 82 | 83 | 84 | private PagerDuty sut; 85 | 86 | @Before 87 | public void setUp() throws ClientProtocolException, IOException 88 | { 89 | MockitoAnnotations.initMocks(this); 90 | when(messageFactoryMock.createTriggerMessage(contextMock)).thenReturn(messageMock); 91 | when(objectMapperMock.writeValueAsString(messageMock)).thenReturn("{test='json'}"); 92 | when(httpClientMock.execute(any(HttpPost.class))).thenReturn(httpResponseMock); 93 | when(entityMock.getContent()).thenReturn(contentMock); 94 | when(httpResponseMock.getEntity()).thenReturn(entityMock); 95 | when(objectMapperMock.readValue(contentMock, PagerDutyResponse.class)) 96 | .thenReturn(pagerDutyResponseMock); 97 | sut = 98 | new PagerDuty( 99 | streamServiceMock, 100 | configMock, 101 | httpClientMock, 102 | objectMapperMock, 103 | messageFactoryMock, 104 | loggerMock); 105 | } 106 | 107 | @Test 108 | public void testSuccessfulTriggerAttempt() throws IOException 109 | { 110 | // Setup 111 | ArgumentCaptor postEntityCaptor = ArgumentCaptor.forClass(HttpPost.class); 112 | 113 | // Execute 114 | PagerDutyResponse result = sut.trigger(contextMock); 115 | 116 | // Assert 117 | verify(httpResponseMock).close(); 118 | verify(httpClientMock).execute(postEntityCaptor.capture()); 119 | verify(messageFactoryMock).createTriggerMessage(contextMock); 120 | assertEquals("Wrong Response Object", pagerDutyResponseMock, result); 121 | assertEquals( 122 | "Wrong Payload", 123 | "{test='json'}", 124 | IOUtils.toString( 125 | postEntityCaptor.getValue().getEntity().getContent(), 126 | StandardCharsets.UTF_8)); 127 | } 128 | 129 | @Test 130 | public void testSuccessfulClose() throws IOException 131 | { 132 | // Execute 133 | sut.close(); 134 | 135 | // Assert 136 | verify(httpClientMock, atMostOnce()).close(); 137 | } 138 | 139 | @Test (expected = IOException.class) 140 | public void testExceptionWhenClosing() throws IOException 141 | { 142 | // Set up 143 | doThrow(IOException.class).when(httpClientMock).close(); 144 | 145 | // Execute 146 | sut.close(); 147 | } 148 | 149 | @Test (expected = IllegalStateException.class) 150 | public void testTriggerAttemptWithException() throws IOException 151 | { 152 | // Setup 153 | when(httpClientMock.execute(any(HttpPost.class))).thenThrow(IOException.class); 154 | 155 | // Execute 156 | sut.trigger(contextMock); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/web/PagerDutyNotificationForm.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import lodash from 'lodash'; 4 | 5 | import { Input } from 'components/bootstrap'; 6 | import FormsUtils from 'util/FormsUtils'; 7 | 8 | class PagerDutyNotificationForm extends React.Component { 9 | static propTypes = { 10 | config: PropTypes.object.isRequired, 11 | validation: PropTypes.object.isRequired, 12 | onChange: PropTypes.func.isRequired, 13 | }; 14 | 15 | static defaultConfig = { 16 | url: '', 17 | }; 18 | 19 | propagateChange = (key, value) => { 20 | const { config, onChange } = this.props; 21 | const nextConfig = lodash.cloneDeep(config); 22 | nextConfig[key] = value; 23 | onChange(nextConfig); 24 | }; 25 | 26 | handleChange = (event) => { 27 | const { name } = event.target; 28 | this.propagateChange(name, FormsUtils.getValueFromInput(event.target)); 29 | }; 30 | 31 | render() { 32 | const { config, validation } = this.props; 33 | 34 | return ( 35 | 36 | 45 | 53 | 62 | 71 | 80 | 81 | ); 82 | } 83 | } 84 | 85 | export default PagerDutyNotificationForm; 86 | -------------------------------------------------------------------------------- /src/web/PagerDutyNotificationSummary.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | import CommonNotificationSummary from 'components/event-notifications/event-notification-types/CommonNotificationSummary'; 5 | 6 | class PagerDutyNotificationSummary extends React.Component { 7 | static propTypes = { 8 | type: PropTypes.string.isRequired, 9 | notification: PropTypes.object, 10 | definitionNotification: PropTypes.object.isRequired, 11 | }; 12 | 13 | static defaultProps = { 14 | notification: {}, 15 | }; 16 | 17 | render() { 18 | const { notification } = this.props; 19 | 20 | return ( 21 | 22 | 23 | 24 | Routing Key 25 | {notification.config.routing_key} 26 | 27 | 28 | Use Custom Incident Key 29 | {notification.config.custom_incident} 30 | 31 | 32 | Incident Key Prefix 33 | {notification.config.key_prefix} 34 | 35 | 36 | Client Name 37 | {notification.config.client_name} 38 | 39 | 40 | Client URL 41 | {notification.config.client_url} 42 | 43 | 44 | 45 | ); 46 | } 47 | } 48 | 49 | export default PagerDutyNotificationSummary; 50 | -------------------------------------------------------------------------------- /src/web/index.jsx: -------------------------------------------------------------------------------- 1 | import webpackEntry from 'webpack-entry'; 2 | 3 | import { PluginManifest, PluginStore } from 'graylog-web-plugin/plugin'; 4 | 5 | import PagerDutyNotificationForm from './PagerDutyNotificationForm'; 6 | import PagerDutyNotificationSummary from './PagerDutyNotificationSummary'; 7 | 8 | 9 | PluginStore.register(new PluginManifest({}, { 10 | 11 | eventNotificationTypes: [ 12 | { 13 | type: 'pagerduty-notification-v1', 14 | displayName: 'PagerDuty Notification', 15 | formComponent: PagerDutyNotificationForm, 16 | summaryComponent: PagerDutyNotificationSummary, 17 | defaultConfig: { 18 | routing_key: '', 19 | custom_incident: true, 20 | key_prefix: 'Graylog/', 21 | client_name: 'Graylog', 22 | client_url: '', 23 | }, 24 | } 25 | ], 26 | })); 27 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const PluginWebpackConfig = require('graylog-web-plugin').PluginWebpackConfig; 2 | const loadBuildConfig = require('graylog-web-plugin').loadBuildConfig; 3 | const path = require('path'); 4 | 5 | // Remember to use the same name here and in `getUniqueId()` in the java MetaData class 6 | module.exports = new PluginWebpackConfig('org.graylog.plugins.pagerduty.PagerDutyNotificationPluginPlugin', loadBuildConfig(path.resolve(__dirname, './build.config')), { 7 | // Here goes your additional webpack configuration. 8 | }); 9 | --------------------------------------------------------------------------------