check_mysql.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*****************************************************************
  2. *
  3. * Program: check_mysql.c
  4. * License: GPL
  5. *
  6. * Written by Tim Weippert
  7. * (based on plugins by Ethan Galstad and MySQL example code)
  8. *
  9. * Command line: check_mysql <host> [user] [passwd]
  10. * <host> can be the FQDN or the IP-Adress
  11. * [user] and [passwd] are optional
  12. *
  13. * Description:
  14. *
  15. * This plugin attempts to connect to an MySQL Server
  16. * with the optional specified parameters user and passwd.
  17. * Normaly the host and a user HAVE to assigned.
  18. *
  19. * The plugin returns
  20. * STATE_OK and the Version Number of the Server when all is fine
  21. * STATE_CRITICAL if the Connection can't be esablished
  22. * STATE_WARNING if the connection was established but the
  23. * program can't get the Versoin Number
  24. * STATE_UNKNOWN if to many parameters are given
  25. *
  26. * Copyright (c) 1999 by Tim Weippert
  27. *
  28. * Changes:
  29. * 16.12.1999: Changed the return codes from numbers to statements
  30. *
  31. *******************************************************************/
  32. #include "../common/config.h"
  33. #include "../common/common.h"
  34. #include "mysql.h"
  35. MYSQL mysql;
  36. int main(int argc, char **argv)
  37. {
  38. uint i = 0;
  39. char *host;
  40. char *user;
  41. char *passwd;
  42. char *status;
  43. char *version;
  44. if ( argc > 4 ) {
  45. printf("Too many Arguments supplied - %i .\n", argc);
  46. printf("Usage: %s <host> [user] [passwd]\n", argv[0]);
  47. return STATE_UNKNOWN;
  48. }
  49. (host = argv[1]) || (host = NULL);
  50. (user = argv[2]) || (user = NULL);
  51. (passwd = argv[3]) || (passwd = NULL);
  52. if (!(mysql_connect(&mysql,host,user,passwd))) {
  53. printf("Can't connect to Mysql on Host: %s\n", host);
  54. return STATE_CRITICAL;
  55. }
  56. if ( !(version = mysql_get_server_info(&mysql)) ) {
  57. printf("Connect OK, but can't get Serverinfo ... something wrong !\n");
  58. return STATE_WARNING;
  59. }
  60. printf("Mysql ok - Running Version: %s\n", version);
  61. mysql_close(&mysql);
  62. return STATE_OK;
  63. }