bulkevent.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package main
  2. import (
  3. "strconv"
  4. "time"
  5. "git.wecise.com/wecise/odbserver/odb"
  6. "gitee.com/wecisecode/util/logger"
  7. )
  8. // CGO_ENABLED=1 go run --ldflags '-linkmode external -extldflags "-static"' bulkevent.go
  9. // #cgo LDFLAGS: -L/opt/odbserver/sqlite -lsqlite -ldl
  10. // #include "/opt/odbserver/sqlite/sqlite.h"
  11. // #include <stdint.h>
  12. // #include <stdlib.h>
  13. // extern int64_t uhaha_seed;
  14. // extern int64_t uhaha_ts;
  15. // void uhaha_begin_reader();
  16. // void uhaha_end_reader();
  17. func main() {
  18. g, err := odb.New(&odb.Option{Cache: odb.CacheAll, Keyspace: "matrix", DisableInitialHostLookup: true}) // For aliyun
  19. //g, err := odb.New(&odb.Option{Cache:odb.CacheAll})
  20. if err != nil {
  21. logger.Fatal(err)
  22. }
  23. cstru := g.Class("/matrix/devops/alert_status")
  24. if rtn, _, err := g.Query(`select * from /matrix/devops/alert_status limit -1`); err == nil {
  25. for j, row := range rtn {
  26. delete(row, "id")
  27. for i := 1; i < 20; i++ {
  28. //row["serverserial"] = "hello2"+strconv.Itoa(j*20+i)
  29. logger.Warnf("serverserial => %d", (j+1)*900+i)
  30. row["serverserial"] = i*j + i + j
  31. row["type"] = i
  32. row["node"] = "wecise" + strconv.Itoa(i)
  33. if err := cstru.ID(g, row); err != nil {
  34. logger.Error(err)
  35. }
  36. if cqls, err := g.ObjectMap2Cql(cstru, row, false); err == nil {
  37. for i := 0; i < len(cqls); i++ {
  38. if err := cqls[i].Exec(); err != nil {
  39. logger.Error(err)
  40. }
  41. }
  42. }
  43. time.Sleep(100 * time.Millisecond)
  44. }
  45. }
  46. } else {
  47. logger.Error(err)
  48. }
  49. }
  50. /*
  51. [
  52. {
  53. "graph": {
  54. "nodes": [
  55. {
  56. "_icon": "linux",
  57. "class": "/matrix/entity/linux",
  58. "id": "linux:h2"
  59. },
  60. {
  61. "_icon": "cassandra",
  62. "class": "/matrix/entity/cassandra",
  63. "id": "cassandra:c1"
  64. },
  65. {
  66. "_icon": "biz",
  67. "class": "/matrix/entity/biz",
  68. "id": "biz:b1"
  69. },
  70. {
  71. "_icon": "linux",
  72. "class": "/matrix/entity/linux",
  73. "id": "linux:h1"
  74. }
  75. ],
  76. "edges": [
  77. {
  78. "class": "contain",
  79. "id": "biz:b1-linux:h1",
  80. "source": "biz:b1",
  81. "target": "linux:h1"
  82. },
  83. {
  84. "class": "contain",
  85. "id": "biz:b1-linux:h2",
  86. "source": "biz:b1",
  87. "target": "linux:h2"
  88. },
  89. {
  90. "class": "contain",
  91. "id": "linux:h1-cassandra:c1",
  92. "source": "linux:h1",
  93. "target": "cassandra:c1"
  94. }
  95. ],
  96. "paths": null,
  97. "pathtags": null
  98. }
  99. }
  100. ]
  101. */